views:

130

answers:

1

I want to mimic the behavior of the Mail app when no results are found from the UISearchBar, and show a cell with a link to call a method. I can't figure out (or find anywhere) how to do so.

The closest I think I've come is the following (which I've added into my code)

if ([self.keys count] == 0){
    [self.tableView beginUpdates];
    [self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath] withRowAnimation:UITableViewRowAnimationBottom];
    [self.tableView endUpdates];
}
[tableView reloadData];
A: 

I believe something like that should work but your uiTableViews:rowsInSection: and such methods still need to return the right count, and cellForRowAtIndexPath needs to do the right thing too. Since it has to do that anyway, you might just want to set some flag and call reloadData on the table view. (In fact, without the cellForRowAtIndexPath the reloadData is probably just clearing the table again.)

Nimrod
What I ended up doing was adding a flag that said whether or not I was showing a table row or my row. Then updated numberOfRows and numberOfSections to return 1 if that flag was set. And in cellForRow, check that flag before displaying the cell and set it to how I want.
Jamie