刷新表视图行

发布于 2024-07-27 22:00:05 字数 274 浏览 2 评论 0原文

我有一个 UISegmentedControl 来更改表视图中的数据。

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

假设我为选项卡一显示 5 行,为选项卡二显示 2 行。 单击第二个选项卡时,前两行将获取新值,但第 3 行至第 5 行的第一个选项卡中的旧数据仍然保留。 我怎样才能清除它们?

I have a UISegmentedControl that changes the data in the table view.

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

Let's say that I display 5 rows for tab one, 2 rows for tab two. When the second tab is clicked the first two rows get new values but the old data from tab one for rows 3 to 5 remains. How can I clear them out ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

熊抱啵儿 2024-08-03 22:00:06

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

我遇到了这个问题,如果我理解正确的话,更新不会删除单元格。 因此,只需删除它们,然后调用更新即可。 祝你好运!

Here's a quick sample code to check out: iPhoneCoreDataRecipes

On topic, here is one of the sweetest provided methods:

// 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];
}

I ran into this problem, if I understand you properly, that updating doesn't remove cells. So just remove them and then call update. Good luck!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文