I have hidden my navigation bar in my table view controller, but after selecting the search bar and then dismissing it with Cancel it shows the navigation bar again. I tried
-(void)searchBarTextDidEndEditing:(UISearchBar *)searchBar {
self.navigationController.navigationBar.hidden = YES;
}
But it did not work, it did hide the navigation bar from the detail view though, but that was not desired.
In storyboard I have a tabBarController --> navigationController --> tableView --> detailview.
EDITED:
My code:
-(BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString
{
[self filterContentForSearchText:searchString
scope:[[self.searchDisplayController.searchBar scopeButtonTitles]
objectAtIndex:[self.searchDisplayController.searchBar
selectedScopeButtonIndex]]];
return YES;
}
- (void)filterContentForSearchText:(NSString*)searchText scope:(NSString*)scope
{
NSPredicate *resultPredicate = [NSPredicate predicateWithFormat:@"name contains[c] %@", searchText];
searchResults = [_truckArray filteredArrayUsingPredicate:resultPredicate];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
if (tableView == self.searchDisplayController.searchResultsTableView) {
return 1;
} else {
return [_sectionTitles count];
}
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if (tableView == self.searchDisplayController.searchResultsTableView) {
if (section == 0) {
[_sectionTitles replaceObjectAtIndex:0 withObject:@""];
[tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
return [searchResults count];
} else {
return 0;
}
} else {
NSString *sectionName = [_sectionTitles objectAtIndex:section];
NSArray *sectionArray = [_sections objectForKey:sectionName];
return [sectionArray count];
}
}
In cellForRowAtIndexPath:
Item *item = nil;
if (tableView == self.searchDisplayController.searchResultsTableView) {
item = [searchResults objectAtIndex:indexPath.row];
} else {
NSString *sectionTitle = [_sectionTitles objectAtIndex:indexPath.section];
NSArray *sectionArray = [_sections objectForKey:sectionTitle];
item = [sectionArray objectAtIndex:indexPath.row];
}