UISearchBar in UINavigatioBar titleView with SearchDisplayController

I'm trying to create a search bar in the title bar of the navigation bar (along with some buttons on the left and right), the whos function should reflect something like a Facebook iOS search bar.

The problem I am facing is that searchResultsTableView never appears when I click on the search bar.

@property (strong, nonatomic) UISearchBar *searchBar;
@property (strong, nonatomic) UISearchDisplayController *searchController;

in my view DidLoad I have

self.searchBar = [[UISearchBar alloc]init];
self.searchBar.delegate=self;
self.searchController=[[UISearchDisplayController alloc] initWithSearchBar:self.searchBar
                                                        contentsController:self];
self.searchController.delegate=self;
self.searchController.searchResultsDataSource = self;
self.searchController.searchResultsDelegate =self;

self.navigationItem.titleView = self.searchBar;

This does not display the presentation of the result table when you click on it and does not expand the panel.

However, if I put the searchBar in the headview of the table, everything works fine:

self.tableView.tableHeaderView = self.searchBar;

I also tried:

self.searchController.displaysSearchBarInNavigationBar = YES;

but it does not extend the search bar to the entire navigation bar and does not smooth / display the result of the TableView after the first time.

Any clarification / help would be greatly appreciated :)

Thank,

+4

All Articles