Bob
Bob

Reputation: 579

Locking UISearchBar to top of a TableView

I am new to iOS development and have been trying to find a way to lock a UISearchBar to the top of a TableView. When I add one using the Storyboard, it scrolls with the table. I need it to be fixed at the top so that when a search term is input, it retrieves some data and displays them in the table cells.

I have researched this for hours and although there appears to be many questions and answers on this topic, I can't find one that works for me. I tried adding a TableView (and a cell) to the bottom part of a UIViewController and a View with a UISearchbar at the top. But when I assign my subclass of UITableViewController to this, I get "'NSInternalInconsistencyException', reason: '-[UITableViewController loadView] loaded the "vAF-gB-z7z-view-IYZ-TB-71E" nib but didn't get a UITableView.'

If I set it to a UIViewController it doesn't crash, but now I don't have control over my table.

Can anyone help me to make this work?

Upvotes: 1

Views: 1697

Answers (2)

rdelmar
rdelmar

Reputation: 104092

You need to use a UIViewController if you don't want the table view to take up the whole screen. So, what you did setting up your view was correct, but you want that controller to be a subclass of UIViewController. You should create an IBOutlet in the controller, and hook it up to the table view, and then add all the data source methods and delegate methods that you normally get with a table view controller.

Upvotes: 4

Jessica
Jessica

Reputation: 1498

This is very simple. Drag and drop the Search Box inside the ViewController below TableView cell. Click on "Show Document Online" button and drag the Search box to move up the hierarchy.

Upvotes: 1

Related Questions