我在我的应用中使用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
,它正在获得正确的搜索结果。
我没有在tableview中看到过滤后的值。如果输入错误的搜索文本,我会看到“无结果”。但是对于正确的搜索文本,表格视图显然是空的。
任何人都可以帮助我做些什么吗?
提前致谢!!
答案 0 :(得分: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];
}
答案 1 :(得分:0)
Write the above code then Reload the table in the source code
[tableView reloadData];