您的位置:首页 > 移动开发 > IOS开发

iOS开发bug消灭之:Invalid update: invalid number of rows in section 0.

2016-10-05 10:14 531 查看

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 = UITableViewRowAction(style: .default, title: "删除", handler: {(action,indexPath) -> Void in
//移除数据源
let realm = try! Realm()
try! realm.write {
realm.delete(self.employees[indexPath.row])
}
self.tableView.deleteRows(at: [indexPath], with: .fade)
})


注意事项:数据源要根据实际情况加以删除

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐