在表视图中实现搜索栏

时间:2017-06-30 11:19:30

标签: ios objective-c uitableview uisearchbar

此函数给出编译时错误

-(BOOL)searchDisplayController:(UISearchDisplayController *)controller 
shouldReloadTableForSearchString:(NSString *)searchString
{
    [self filterContentForSearchText:searchString 
                               scope:[[self.searchDisplayController.searchBar scopeButtonTitles]
                                      objectAtIndex:[self.searchDisplayController.searchBar
                                                     selectedScopeButtonIndex]]];

    return YES;
}

此行的编译器错误

[self filterContentForSearchText:searchString 
                           scope:[[self.searchDisplayController.searchBar scopeButtonTitles] objectAtIndex:[self.searchDisplayController.searchBar selectedScopeButtonIndex]]];

ARC语义问题

  

'ViewController'没有可见的@interface声明选择器   'filterContentForSearchText:范围:

如何删除此错误? 我正在关注本教程here。本教程中的确切功能是在xcode中给出错误。

1 个答案:

答案 0 :(得分:0)

实施此

 - (void)filterContentForSearchText:(NSString*)searchText scope:(NSString*)scope
    {
        NSPredicate *resultPredicate = [NSPredicate 
                                        predicateWithFormat:@"SELF contains[cd] %@",
                                        searchText];

        searchResults = [yourArray filteredArrayUsingPredicate:resultPredicate];
}