你的位置:首页 > 软件开发 > 操作系统 > NSInternalInconsistencyException attempt to delete row 2 from section 4 which only contains 0 rows before the update 问题原因

NSInternalInconsistencyException attempt to delete row 2 from section 4 which only contains 0 rows before the update 问题原因

发布时间:2017-02-26 12:00:09
insertRowsAtIndexPaths 和 deleteRowsAtIndexPaths 同 numberOfRowsInSection 的关系如果不处理好这个关系,大概所有的问题都是这样的:Terminating app due to uncaught exc ...

insertRowsAtIndexPaths 和 deleteRowsAtIndexPaths 同 numberOfRowsInSection 的关系

如果不处理好这个关系,大概所有的问题都是这样的:

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

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'attempt to delete row 2 from section 4 which only contains 0 rows before the update'

大楖是说,numberOfRowsInSection 返回的数字和 insert / delete 后,section 所包含的行数不一致。

在 tableView 的 endUpdates 方法之前,应该对标志变量做处理。endUpdates 后,会重新刷新 tableView ,numberOfRowsInSection 会重新被调用。

解决方法有两种:

1,如上所说处理好标志变量:

if ([wwtableview numberOfRowsInSection:4]>2) {}

2,tableview beginUpdates之前的行数对应的是前一个数据源,开始reloadcell时tableview并不知道数据源发生了变化

[wwtableview reloadData]

 


原标题:NSInternalInconsistencyException attempt to delete row 2 from section 4 which only contains 0 rows before the update 问题原因

关键词:

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

可能感兴趣文章

我的浏览记录