ITeye博客

UISearchDisplayController使用

mrjeye · 2012-01-14 10:53 · iphone · 移动开发 · Markdown

用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;

用于重新填充搜索出的数据

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。