- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个分页 tableView
,每次用户滚动时都会加载一个新页面,有点像 instagram 提要。 tableView
的重新加载发生在获取新页面后的回调中。代码看起来像这样:
func fetchNewPage() {
ws.fetchNewPage(completion: { () -> Void in {
updateDataSource()
self.tableView.reloadData()
})
}
同时,tableView
中的单元格应在用户点击它们时更新(它们会更改其背景颜色)。这发生在调用 WS 之后。代码看起来像这样:
func markAsSeen(indexPath: NSIndexPath) {
ws.markAsSeen(completion: { () -> Void in {
self.tableView.reloadRowsAtIndexPaths([indexPath], withRowAnimation: .None)
})
}
我的问题是 dataSource
可以在执行 markAsSeen
完成 block 时更改元素的数量。然后应用程序崩溃并出现此异常:
Fatal Exception: NSInternalInconsistencyException
Invalid update: invalid number of rows in section 0. The number of rows contained in an existing section after the update (50) must be equal to the number of rows contained in that section before the update (25), plus or minus the number of rows inserted or deleted from that section (1 inserted, 1 deleted) and plus or minus the number of rows moved into or out of that section (0 moved in, 0 moved out).
所以,我的问题是,您是否知道如何同步这两个 block ,以便应用程序不再崩溃,但行也会得到更新。
非常感谢
最佳答案
您关于同步的想法是正确的。作为一个选项,您可以在主队列上执行数据源更新。在这种情况下,数据源和 UI 更新将按顺序排队和执行,因为数据的结果更改将是可预测和一致的。
另外值得一提的是,所有 UI 调用都必须在主线程上执行。从您的代码中并不清楚这是真的。
关于ios - `reloadRowsAtIndexPath` 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31132031/
这段代码的问题(在 func tableView(tableView: UITableView, commitEditingStyleeditingStyle: UITableViewCellEdit
我有一个分组 TableView ,我想在其中重新加载特定行。当我调用 reloadRowsAtIndexPaths: 时,该行从 TableView 中完全消失。我还需要做其他事情吗? //this
我将 UITableView 与静态单元格一起使用。如果我使用reloadData,那么一切都OK。 如果我尝试reloadRowsAtIndexPaths它会隐藏行。如果我上下拖动 tableVie
我看过很多这样的代码,但不确定如何实际实现它。 [self.tableView beginUpdates]; [self.tableView reloadRowsAtIndexPaths:@[inde
我有一个 UITableView,它的数据源通过调用 PHP 脚本得到更新,如果有任何数据要更新,响应会向数组添加一个新对象。如果通过 TimeStamp 添加了新项目,并且如果有新数据,那么新数据将
在我的应用程序中,当像这样重新加载表格 View 单元格时 let editItemView = view.viewWithTag(12) as! UITableView let indexPath
我正在尝试在我的 UITableCells 上添加赞成票和反对票 我的意思是: 每当我点击向上和向下按钮时,它应该立即更新单元格 这是我填充表格的方式: 我的 UITableView 中的代码块 ..
我有一个分页 tableView,每次用户滚动时都会加载一个新页面,有点像 instagram 提要。 tableView 的重新加载发生在获取新页面后的回调中。代码看起来像这样: func fetc
我有一个表格 View 。每个单元格每 10 秒更新一次。每个单元格都有 editActions,例如: 但是当我向左滑动以查看操作时,同时调用 reloadRowsAtIndexPaths 函数时,
我的 ViewController 中有一个 UITableView。其中一个单元格可以接入另一个 TableViewController 以允许选择一个值。 我想在从被调用者 ViewControl
我正在尝试覆盖 tableView 单元格的方法 reloadRowAtIndexPath。 我想做的和你覆盖 cellForRowAtIndexPath 时一样: func tableView(ta
我正在尝试重新加载单个 tableViewCell,但每次我这样做时它都会滚动到顶部...我没有添加或删除单元格,我只是想更改所选单元格的颜色。 这就是我在 cellForRowAtIndexPath
我在我的 iOS 应用程序中使用 UITableView,最近遇到了一个奇怪的问题。 假设我的表结构如下: section 1 header row section 2 header section
我有一个表格 View ,其中每个单元格都包含播放音频文件的功能。我正在尝试复制在语音备忘录程序中找到的单元格: 我正在使用 UISlider 提供播放栏,并且我有当前时间和剩余时间的文本标签。我希望
我有一个 UITableview,可以延迟加载所有不同大小的图像。加载图像时,我需要更新特定的单元格,因此我发现我需要使用 reloadRowsAtIndexPaths。但是当我使用这个方法时,它仍然
我正在尝试使用按钮删除单元格。 这是单元格的实现。 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRo
我有一个 UITableView,其中包含一个包含 UIWebView 的自定义单元格。一旦 webview 完成加载 html 内容,我就会尝试以正确的高度重新加载单元格。 override fun
背景:在 tableView 中,每个单元格都包含一个显示为图像的按钮。我想展示的效果是,当我点击图片(实际上是按钮)时,按钮的图片会变成另一个图片。 错误:假设有很多数据(超过一页),如果我点击一个
我试图同时绑定(bind)两个 Action 。其中之一动态更改 heighForRow,第二个动态地拉伸(stretch) View.frame。两者都通过相同的点击被解雇。问题是当我尝试添加 re
我有一个 tableviewcell在RegisterViewController ,当我点击它时,它会推送到 SelectCityViewController我可以从 uipickerview 中选
我是一名优秀的程序员,十分优秀!