Invalid update: invalid number of rows in section 0.
swift版本:3.0
Xcode版本:8.0
错误全文:
Invalid update: invalid number of rows in section 0. 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 (8), plus or minus the number of rows inserted or deleted from that section (0 inserted, 1 deleted) and plus or minus the number of rows moved into or out of that section (0 moved in, 0 moved out).
错误原因:删除TableView Cell的时候没有删除对应的数据源
错误源码:
let deleteAction = UITableViewRowAction(style: .default, title: "删除", handler: {(action,indexPath) -> Void in
let realm = try! Realm()
self.tableView.deleteRows(at: [indexPath], with: .fade)
})
修正源码:
let deleteAction = UITableViewRowAct

这篇博客探讨了在iOS开发中遇到的'Invalid update: invalid number of rows in section 0.'错误,该错误源于在删除TableView Cell时未同步删除数据源。文章详细解释了错误原因,并提供了错误及修正后的源码示例,强调了更新数据源的重要性。
最低0.47元/天 解锁文章

被折叠的 条评论
为什么被折叠?



