views:

3837

answers:

5

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.

+1  A: 

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...

Mugunth Kumar
A: 

Ok, I have found how to solve it. In my case, the problem was due to the fact that I was using a controller embedded within the UITabBarController as one of its managed tabs (i.e. as a child).

Removing the controller from the UITabBarController, then adding an UINavigationController to the UITabBarController instead, and finally putting my controller as a child of the UINavigationController solved completely the issue.

I do not understand why this is so (there is no related information in the documentation, as often happens); however, it now works like a charm. With kind regards.

unforgiven
A: 

Could you describe it sharpenly? I have same problem. But SearchBar still doesn't appears.

Thank you.

Sartharian
The interface was laid out using Interface Builder, so that you should try to replicate the steps I have outlined. Of course, you can also do this programmatically. Just make sure that the following parent-child relationships are in place in IB: UITabBarController tab -> UINavigationController -> your controller exposing the searchBar.
unforgiven
+1  A: 

I had a similar issue

To solve I had to do one additional step to unforgivens answer In my main nib

1) create a UITabController 2) Then I dragged out a UINavigational Controller into the tab controller 3) Then dragged out a UITableViewController into the NavigationalController as a child 4) Then changed (3) class to be my MyTableWithSearchBarViewController in the inspector - check if the nib name is correct and change this if necessary in the inspector as well 5) I then had to delete the tableView which is automatically created by IB in step (3). Only then would the search bar show correctly...

If in step 3 I dragged out a different controller onto the stage or left the tableView there it would only ever display the table and not the search bar

weird

joneswah
+1  A: 

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.

tomtrapeze