最好的處理方式就是重寫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; }