【问题标题】:Refreshing Table View Rows刷新表视图行
【发布时间】:2010-11-13 12:43:26
【问题描述】:

我有一个UISegmentedControl,它可以更改表格视图中的数据。

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

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

【问题讨论】:

  • 我假设您在 iPhone 上使用 object-c。请添加这些标签。另外,你是说你有一个 UITabViewController 每个选项卡有 1 个表视图吗?此外,为了便于阅读,请突出显示您的代码,然后点击代码格式按钮,以使其正确显示。

标签: ios uitableview cocoa-touch reload


【解决方案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];
}

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

【讨论】:

  • @A-Live 我意识到它正在做一些棘手的事情;你有什么特别要说的吗?
  • 它什么也不做,初始值与最终值匹配。还应该在循环之前或内部对索引进行验证,以防止超出范围。
  • 我明白你在说什么;诚然,这段代码有很多问题。我不认为它是我写的,但我当然可能已经编辑过它。我对循环进行了合理的更改,并将其他需求留给读者作为练习。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-07-27
  • 2011-08-31
  • 2011-03-18
  • 2011-05-04
  • 2011-10-23
相关资源
最近更新 更多