当UISearchBar没有结果时(如Mail app),在UITableViewCell中添加一个按钮

时间:2010-01-24 07:43:44

标签: iphone cocoa-touch uikit uitableview uisearchbar

我想在UISearchBar中找不到结果时模仿Mail应用程序的行为,并显示一个带有调用方法链接的单元格。我无法弄清楚(或找不到任何地方)如何做到这一点。

我认为我最接近的是以下(我已将其添加到我的代码中)

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

1 个答案:

答案 0 :(得分:0)

我相信这样的东西应该可以工作但你的uiTableViews:rowsInSection:这样的方法仍然需要返回正确的计数,而且cellForRowAtIndexPath也需要做正确的事情。既然它必须这样做,你可能只想设置一些标志并在表视图上调用reloadData。 (事实上​​,如果没有cellForRowAtIndexPath,reloadData可能只是再次清除表。)