How to use UISearchDisplayController from controller in UITabBar controller?

I have a UITabBar controller that manages multiple controllers (using SDK 3.0). One of them is the tableView controller, and I need to provide a search option using the UISearchDisplayController. All my code is based on the example of Apple TableSearch. However, when you click on the tab, the tableView controller is displayed with the related content, but the searchBar is not displayed. I checked xib in IB to make sure all outputs are set correctly, but no matter what I try to execute self.searchDisplayController is always zero and the search bar does not appear.

In practice, I replicated MainView.xib from the TableSearch example and set the file owner class to the correct controller class for the tab. The outputs are sets, as in the MainView.xib example. Am I missing any important step or is something wrong?

Thanks in advance.

+7
iphone uisearchbar uisearchdisplaycontroller
source share
7 answers

Ok, I found how to solve it. In my case, the problem was that I used the controller built into the UITabBarController as one of the managed tabs (i.e. as a child).

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

I don’t understand why this is so (the documentation does not contain relevant information, as often happens); however, it now works like a charm. Sincerely.

+1
source share

I had the same problem and I came across this solution ...

If you have a table view controller (for example, UISearchDisplayController ) nested in a tab bar or navigation controller using Interface Builder, you need to set the "Thread Name" in the "Attributes Inspector" window.

The name of the thread will be the one that stores the table view and has a controller (eg. UISearchDisplayController ) as the owner of the file.

+5
source share

I also have this problem :( Is the search bar hidden behind the table?

@unforgiven, have you tried this ...?

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

This manually creates a search bar and it works. But I am making some kind of stupid mistake in IB that the SearchBar does not appear, although my connections are fine .: - (

Refresh this post if you get an answer ...

+1
source share

I had a similar problem

To decide, I had to take another step to forgive the answer In my main knee

1) create a UITabController 2) Then I pulled the UIN_virtual controller into the tab controller 3) Then pulled out the UITableViewController in the NavigationalController as a child 4) Then the class changed (3) to my MyTableWithSearchBarViewController in the inspector - check the correct name and change it if necessary, if necessary in the inspector 5) Then I had to delete the View table, which is automatically created by IB in step (3). Only then will the search bar be displayed correctly ...

If in step 3 I pulled another controller onto the scene or left the tableView there, it would only display the table, not the search bar

weird

+1
source share

Tomtrapeze has the correct answer if your nib file contains a UITableViewController. But if you load the UITableViewController into code - for example, push it onto the UINavigationController stack - the solution is slightly different.

When initializing a UITableViewController or subclass, you need to use the -initWithNibName: bundle: form initializer form and specify the name of your nib file. Alternatively, you can use the standard -initWithStyle: initializer and manually set the nibName property before loading the view.

If the nibName property is not set when the view is loaded, the UITableViewController will not use the normal UIViewController nib search logic. It will just load the standard UITableView.

+1
source share

I recently found out that I can load NIB files using [[MyViewController alloc] initWithNibName:nil bundle:nil]; when the NIB file has the same name as the class (i.e. MyViewController.xib ). It turns out that initializing this method causes UISearchBar and UISearchBarDisplayController` to not be displayed. When I initialized the view controller by typing the class name, my search bar appeared correctly. Initially, I thought that this was due to the way I represent the view controller, but was glad that it was not.

 PGWSearchViewController *searchVC = [[PGWSearchViewController alloc] initWithNibName:@"PGWSearchViewController" bundle:nil]; searchVC.modalPresentationStyle = UIModalPresentationFullScreen; searchVC.modalTransitionStyle = UIModalTransitionStyleCoverVertical; [self presentViewController:searchVC animated:YES completion:^{ }]; 

It uses the iOS SDK 5.1 and Xcode 4.3.1.

+1
source share

Another possible fix that works for me is to initialize the UITableViewController with initWithNibName: bundle:

 SearchEntryTableViewController* searchEntryTableViewController = [[SearchEntryTableViewController alloc]initWithNibName:@"SearchEntryTableViewController" bundle:nil]; 

To nest a UITableViewController in a UINavigationController before putting it in a UITabBarController is not a problem for me ...

0
source share

All Articles