2013-07-03 74 views
1

我在我的应用程序中使用UISearchBar。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

检查,看看你的数组为null – NightSkyCode

+0

有你重装实现代码如下。被过滤的数组是tableview的数据吗? – Vinodh

+0

我的过滤数组不是空,我做了NSLog来查看过滤的值。我在cellForRowAtIndexPath方法中以及在numberOfRowsInSection中看到过滤的数组值。 – user906492

回答

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]; 
    } 
0
Write the above code then Reload the table in the source code 


    [tableView reloadData]; 
+0

[self.tableview reloadData];该方法内没有工作。 – user906492

+0

我已经缩小了这个问题。如果单元格是UITableViewCell,则来自SearchBar的过滤器正在工作。我有一个自定义单元格,我已将UITableViewCell扩展到ECell。使用这个,Filterdata不起作用。任何想法? – user906492

+0

对象重载的tableview – Charlie