1 默认情况下,点击搜索框之后会隐藏NavigationBar,如何取消隐藏呢?

最好的处理方式就是重写UISearchDisplayController的
-(void)setActive:(BOOL)visible animated:(BOOL)animated方法:
首先,自定义一个类CustomSearchDisplayController,继承自UISearchDisplayController,然后在.m文件中重写该方法,并在该方法中主动显示navagationBar

#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;
}

change2hao
96 声望4 粉丝

引用和评论

0 条评论