UISearchDisplayController總結

1 默認狀況下,點擊搜索框以後會隱藏NavigationBar,如何取消隱藏呢?

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

2 當沒有匹配的結果時,默認會在tableView上顯示一個「No Result」的標籤,若是說想自定義這個標籤,能夠在tableview中循環遍歷出該標籤,而後按照你的想法去設置:

- (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;
}
相關文章
相關標籤/搜索