最好的处理方式就是重写UISearchDisplayController的-(void)setActive:(BOOL)visible animated:(BOOL)animated方法:
首先,自定义一个类CustomSearchDisplayController,继承自UISearchDisplayController,而后在.m文件中重写该方法,并在该方法中主动显示navagationBarcode
#import "CustomSearchDisplayController.h" @implementation CustomSearchDisplayController -(void)setActive:(BOOL)visible animated:(BOOL)animated { [super setActive:visible animated:animated]; [self.searchContentsController.navigationController setNavigationBarHidden: NO animated: NO]; } @end
- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString { [self filterContentForSearchText:searchString]; if ([filteredListPinYin count] == 0) { UITableView *tableView1 = self.searchDisplayController.searchResultsTableView; for( UIView *subview in tableView1.subviews ) { if( [subview class] == [UILabel class] ) { UILabel *lbl = (UILabel*)subview; // sv changed to subview. lbl.text = @”没有结果”; } } } // Return YES to cause the search result table view to be reloaded. return YES; }