用UISearchBar初始化,设置代理
检测当前table view,分情况选择需要显示的数据
cellForRowAtIndexPath同样选择
实现
用于重新填充搜索出的数据
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;
用于重新填充搜索出的数据