刷新表视图行

时间:2009-07-23 19:52:02

标签: ios uitableview cocoa-touch reload

我有UISegmentedControl更改表格视图中的数据。

[self.mySexyTableView reloadRowsAtIndexPaths:updatedPaths withRowAnimation:UITableViewRowAnimationTop];

假设我为标签1显示5行,标签2显示2行。单击第二个选项卡时,前两行将获得新值,但第3行到第5行的选项卡中的旧数据仍然存在。我该如何清除它们?

1 个答案:

答案 0 :(得分:1)

以下是一个快速查看示例代码: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];
}

我遇到了这个问题,如果我理解正确,那么更新不会删除单元格。所以只需删除它们然后然后调用更新。祝你好运!