Add a button in a UITableViewCell when UISearchBar has no results (like Mail app)
I want to mimic the behavior of the Mail app when no results are 开发者_JAVA技巧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];
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.)
精彩评论