【问题标题】:iOS Reloading two tableView sectionsiOS重新加载两个tableView部分
【发布时间】:2013-06-05 16:52:29
【问题描述】:

如何在我的 tableView 中重新加载两个不相邻的部分?例如,如果我想重新加载第 0 节和第 4 节。我不能使用

[NSIndexSet indexSetWithIndexesInRange: withRowAnimation:];

因为它会重新加载中间的所有部分,对吧?

我也尝试过连续调用

[NSIndexSet indexSetWithIndex: withRowAnimation:]

但它不起作用,我收到了这个错误:

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of rows in section 1.  The number of rows contained in an existing section after the update (8) must be equal to the number of rows contained in that section before the update (1), plus or minus the number of rows inserted or deleted from that section (0 inserted, 0 deleted) and plus or minus the number of rows moved into or out of that section (0 moved in, 0 moved out).' 

编辑:抱歉,我忘了在更新时提到重新加载的每个部分的行数更改。

【问题讨论】:

  • 如何使用 UITableView beginUpdates & endUpdates & 在中间插入或更新新行?
  • 你看过文档了吗?? -> developer.apple.com/library/ios/documentation/uikit/reference/…: (reloadSections:withRowAnimation:)
  • 是的,我做到了。我看到 reloadSections:withRowAnimation: 需要一个 NSIndexSet。但是我在 NSIndexSet 中看到的创建具有多个索引的集合的唯一方法是使用范围。我想更新两个不相邻的部分。有没有办法创建一个不是由范围组成的 NSIndexSet?我在文档中没有看到方法。

标签: ios tableview reload


【解决方案1】:

我能够通过重新排序我的 reloadSections: 调用来解决我的问题,以便在每次 reloadSections: 调用之前只更改一个部分的数据。

【讨论】:

  • 这让我很烦,似乎一次只重新加载一个部分就可以了。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-07-30
  • 2016-11-09
  • 1970-01-01
  • 1970-01-01
  • 2014-08-24
  • 2020-11-21
相关资源
最近更新 更多