Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use UISearchDisplayController from a controller within an UITabBar controller?

I have an UITabBar controller managing several controllers (using SDK 3.0). One of these is a tableView controller and I need to provide a search capability using the UISearchDisplayController. All of my code is based on Apple TableSearch example. However, when clicking on the tab, the tableView controller appears showing its related content, but no searchBar appears. I have checked the xib in IB to make sure that all of the outlets are properly set, but no matter what I try self.searchDisplayController is always nil and the search bar does not appear.

In practice I have replicated MainView.xib from the TableSearch example and set the file's owner class to the correct controller class for the tab. The outlets are sets as in the example MainView.xib. Am i missing any important step or doing something wrong?

Thank you in advance.

like image 271
Massimo Cafaro Avatar asked Aug 10 '09 23:08

Massimo Cafaro


2 Answers

I had the same issue and happened to stumble upon this solution ...

If you have your table view controller (eg. UISearchDisplayController) nested in a Tab Bar or Navigation controller using Interface Builder, you need to set the "Nib Name" in the "Attributes Inspector" window.

The Nib name will be the one that holds the table view and has the controller (eg. UISearchDisplayController) as the File's Owner.

like image 79
Zach Mathew Avatar answered Nov 01 '22 17:11

Zach Mathew


I too have this issue :( Is the search bar getting hidden behind the tableview?

@unforgiven, did you try this...?

searchBar = [[UISearchBar alloc]initWithFrame:CGRectMake(0, 0, 320, 40)]; 
[self.tableView setTableHeaderView: searchBar];

This manually creates a searchbar and it works. But I'm making some stupid mistake in IB that the SearchBar doesn't show up even though my connections are perfect. :-(

Do update this post if you get the answer...

like image 1
Mugunth Avatar answered Nov 01 '22 18:11

Mugunth