1

I'm using UISearchBar in my app.

- (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];
}

I did NSLog on above "filtered" array, it's getting proper search results.

I don't see the filtered values in the tableview. I see "No results" if I type wrong search text. But for the correct search text, the table view is plain empty.

Can anyone help me what needs to be done?

Thanks in advance!!

Vinodh
  • 5,262
  • 4
  • 38
  • 68
user906492
  • 31
  • 2
  • check to see if your array is null – NightSkyCode Jul 03 '13 at 05:02
  • have you reload the tableview. Is Filtered array is datasouece of tableview ? – Vinodh Jul 03 '13 at 05:06
  • My filtered Array is not null, I did NSLog to see the filtered values. I see the filtered array values in cellForRowAtIndexPath method as well and in numberOfRowsInSection. – user906492 Jul 03 '13 at 05:06
  • I have only one reload call inside viewDidLoad. I'm not sure what you mean by Filtered array is datasource? I didn't explicitly said it as datasource. Please let me know how to do it, if I've missed that. Thanks. – user906492 Jul 03 '13 at 05:14
  • Can you post the `cellForRowAtIndexPath` code ? – Midhun MP Jul 03 '13 at 05:44
  • - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellId= @"eCell"; ECell *cell= [tableView dequeueReusableCellWithIdentifier:CellId]; if (cell==nil) { cell= [[ECell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; } Ex *e; if (tableView== self.searchDisplayController.searchResultsTableView) { e= [filtered objectAtIndex:[indexPath row]]; } else { e= [ee objectAtIndex:indexPath.row]; } cell.company.text= e.companyName; return cell; } – user906492 Jul 03 '13 at 13:51
  • I've narrowed down the problem. If the cell is UITableViewCell, the Filter from SearchBar is working. I have a custom cell, in which I've extended the UITableViewCell to ECell. Using this, Filterdata is not working. Any idea? – user906492 Jul 03 '13 at 15:17
  • Hi user906492, did you solve this issue? I am also using a custom cell and getting empty results. – bashan Aug 08 '13 at 18:47

2 Answers2

0

Please use the following code . And make sure that self.filtered is the datasource of yourtableview . Datasource means array from tableview gets populated

 - (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];
    }
Vinodh
  • 5,262
  • 4
  • 38
  • 68
0
Write the above code  then Reload the table in the source code 


   [tableView reloadData];
Charlie
  • 187
  • 1
  • 12
  • I've narrowed down the problem. If the cell is UITableViewCell, the Filter from SearchBar is working. I have a custom cell, in which I've extended the UITableViewCell to ECell. Using this, Filterdata is not working. Any idea? – user906492 Jul 03 '13 at 15:17
  • tableview of object reload – Charlie Jul 04 '13 at 07:40