Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fixed UISearchBar using UISearchController - Not using header view of UITableView

Is it possible to put UISearchBar of UISearchController somewhere other than header view of UITableView?

In the apple's sample code for UISearchController, following is used.

[self.searchController.searchBar sizeToFit];
self.tableView.tableHeaderView = self.searchController.searchBar; 

Is it possible to position searchBar somewhere else? Say we want to implement a fixed UISearchBar like the one used in contacts app. I've tried this but the searchBar doesn't appear at all.

like image 941
MTRL Avatar asked Mar 22 '15 08:03

MTRL


1 Answers

You can place the UISearchBar of UISearchController in the navigation bar so that it remains fixed

self.searchController.hidesNavigationBarDuringPresentation = NO;
self.searchController.searchBar.searchBarStyle = UISearchBarStyleMinimal;

// Include the search bar within the navigation bar.
self.navigationItem.titleView = self.searchController.searchBar;

self.definesPresentationContext = YES;
like image 188
Praveen Gowda I V Avatar answered Oct 14 '22 22:10

Praveen Gowda I V