I want to add a SearchBar
to my TableView
. I just dragged the UISearchBar
to the header of an UITableView
in IB, and it scrolled with my UITableView
.
I changed to use UITableViewController
now, and when I drag an UISearchBar
in the header
of the UITableView
which is provided with the UITableViewController
, it doesn't show up at all.
Is there a trick?
Kind regards
I get it to work by using two UITableViewDelegate Protocol methods –tableView:viewForHeaderInSection: and –tableView:heightForHeaderInSection: as given below.
Hope it helps.
I just tried it and it worked for me, there shouldn't be a trick. If you want to post a distilled version of your project somewhere I can help you look.
Whenever I define the searchbar in the nib, I dont add it to the table view's header on purpose. Instead I set it in the viewDidLoad function. Retterdesdialogs solution also works, so not sure why he hasn't got more votes.
You can do it programmatically
Hope this helps.
It also depends on how to initialized the tableview controller, if you alloc and init via initWithNib:Bundle method it should still show up. But with the tableview controller I think the default implementation method is initWithStyle. If you alloc'd and init with initWithStyle the nib file will never load.