1

我在我的应用程序中使用 UISearchBar。

- (void)filterContentForSearchText:(NSString*)searchText scope:(NSString*)scope 
{
    [self.filtered removeAllObjects];
    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF.companyName contains[cd] %@",searchText];
    NSArray *tempArray = [ee filteredArrayUsingPredicate:predicate];
    filtered = [NSMutableArray arrayWithArray:tempArray];
}

NSLog在上面的“过滤”数组上做了,它得到了正确的搜索结果。

我没有在表格视图中看到过滤后的值。如果我输入错误的搜索文本,我会看到“无结果”。但是对于正确的搜索文本,表格视图是空的。

谁能帮助我需要做什么?

提前致谢!!

4

2 回答 2

0

请使用以下代码。并确保这self.filtered 是 yourtableview 的数据源。数据源意味着来自 tableview 的数组被填充

 - (void)filterContentForSearchText:(NSString*)searchText scope:(NSString*)scope 
    {
        [self.filtered removeAllObjects];
        NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF.companyName contains[cd] %@",searchText];
        NSArray *tempArray = [ee filteredArrayUsingPredicate:predicate];
        filtered = [NSMutableArray arrayWithArray:tempArray];
   [yourtableview reloadData];
    }
于 2013-07-03T05:34:41.643 回答
0
Write the above code  then Reload the table in the source code 


   [tableView reloadData];
于 2013-07-03T08:08:34.090 回答