I want to hide the Navigation Bar of my page when the user start editing on the searchbar, I also want to show a cancel button.
It is done but my cancel button is not access
You need to use UISearchDisplayController, that will hide navigation bar automatically for you. Here is the code,
-(void) createSearchBar
{
_searchBar = [[SearchBar alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 44)];
_searchBar.delegate = self;
[self.view addSubview:_searchBar];
searchDisplayController = [[UISearchDisplayController alloc] initWithSearchBar:_searchBar contentsController:self];
searchDisplayController.delegate = self;
searchDisplayController.searchResultsDataSource = self;
searchDisplayController.searchResultsDelegate = self;
searchDisplayController.searchResultsTableView.sectionHeaderHeight = 10;
searchDisplayController.searchResultsTableView.sectionFooterHeight = 0;
[searchDisplayController.searchResultsTableView setSeparatorColor:[Color whiteColor]];
}
You will have to implement protocols UISearchBarDelegate, UISearchDisplayDelegate, UITableViewDelegate, UITableViewDataSource in .h file.
also _searchBar & searchDisplayController are variables defined in .h file.