我有一个UISegmentedControl
可以更改表格视图中的数据。
[self.mySexyTableView reloadRowsAtIndexPaths:updatedPaths withRowAnimation:UITableViewRowAnimationTop];
假设我为选项卡一显示 5 行,为选项卡二显示 2 行。单击第二个选项卡时,前两行获取新值,但第 3 到第 5 行的选项卡中的旧数据仍然存在。我怎样才能清除它们?
我有一个UISegmentedControl
可以更改表格视图中的数据。
[self.mySexyTableView reloadRowsAtIndexPaths:updatedPaths withRowAnimation:UITableViewRowAnimationTop];
假设我为选项卡一显示 5 行,为选项卡二显示 2 行。单击第二个选项卡时,前两行获取新值,但第 3 到第 5 行的选项卡中的旧数据仍然存在。我怎样才能清除它们?
这是一个快速的示例代码来检查:iPhoneCoreDataRecipes
关于主题,这是提供的最甜蜜的方法之一:
// If I want to delete the next 3 cells after the one you click
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSMutableArray* indexPaths = [NSMutableArray array];
for (int i = indexPath.row + 1; i < indexPath.row + 4; i++)
{
[indexPaths addObject:[NSIndexPath indexPathForRow:i inSection:0]];
}
[tableView beginUpdates];
[tableView deleteRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationFade];
[tableView endUpdates];
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
我遇到了这个问题,如果我理解正确的话,更新不会删除单元格。所以只需删除它们,然后调用更新。祝你好运!