0

I'm developing an iOS 6 application.

I want to add a search functionallity to a UITableView following this Table Search example from Apple. But, my implementation doesn't work.

On - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath I don't know how to if tableView parameter is searchDisplayController.searchResultsTableView.

Take a look at this screenshot:

enter image description here

As you can see, tableView is a UISearchResultsTableView, but this line:

if ([tableView isEqual:self.searchDisplayController.searchResultsTableView])

It is always false.

Maybe, I need to add an outlet to access seachResultsTableView, but I haven't found that outlet on TableSearch example.

This ViewController.h:

@interface ViewController: UIViewController <UITableViewDelegate, UITableViewDataSource, UISearchDisplayDelegate, UISearchBarDelegate> {

What do I need to do to make it work?

VansFannel
  • 45,055
  • 107
  • 359
  • 626

1 Answers1

0
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}

if(searching) 
{
    cell.textLabel.text = [searchedListOfItems objectAtIndex:indexPath.row];
}
else {

    NSDictionary *dictionary = [self.tableDataSource objectAtIndex:indexPath.row];
    cell.textLabel.text = [dictionary objectForKey:@"Title"];
}

return cell;

if all you're trying to achieve is a normal search then use this.

Sam
  • 390
  • 1
  • 3
  • 15