`
mrjeye
  • 浏览: 173897 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

UISearchDisplayController使用

阅读更多
用UISearchBar初始化,设置代理
UISearchBar *searchBar = [[UISearchBar alloc] init];
    self.tableView.tableHeaderView = searchBar;
    [searchBar sizeToFit];
    searchBar.delegate = self;
    [searchBar release];
    
    searchDisplay = [[UISearchDisplayController alloc] initWithSearchBar:searchBar contentsController:self];
    searchDisplay.delegate = self;
    searchDisplay.searchResultsDataSource = self;
    searchDisplay.searchResultsDelegate = self;


检测当前table view,分情况选择需要显示的数据

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if ([tableView isEqual:self.searchDisplayController.searchResultsTableView]) {
        return self.searchGroupList.count;
    }
    return [self.groupList count];
}


cellForRowAtIndexPath同样选择

实现
- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString;


用于重新填充搜索出的数据
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics