iOS调用reloadRowsAtIndexPaths Crash报异常NSInternalInconsistencyException
来源:互联网 发布:手机取物软件 编辑:程序博客网 时间:2024/06/07 19:29
背景
在更新 TableView 的时候调用[self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:0 inSection:0]] withRowAnimation:UITableViewRowAnimationFade];
crash掉了,报异常attempt to delete row 0 from section 0 which only contains 0 rows before the update
原因
在调用reloadRowsAtIndexPaths
时,依赖于tableView先前的状态已有要更新的cell,它内部是先删除该cell,再重新创建,所以当你在原先没有该cell的状态下调用reloadRowsAtIndexPaths
,会报异常你正在尝试不存在的cell。
简言之,如果你要改变tableView的cell数量,就不要调用更新局部的cell方法。
解决办法
1.使用reloadData
reloadData
是完全重新加载,包括cell数量也会重新计算,不会依赖之前tableView的状态。
2.使用beginUpdates
和 endUpdates
(未自验证,验证者可留言)
- 当你在将要更改cell数量的时候都要通知tableView更新(调用
[tableView beginUpdates];
) - 添加时通知使用方法
(void)insertRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation
- 移除时通知使用方法
(void)deleteRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation
- 当你已经更改cell数量的时候都要告诉tableView更新完毕(调用
[tableView endUpdates];
)
References:
StackOverflow - Crash on reloadRowsAtIndexPath but not on reloadData
StackOverflow - reloadRowsAtIndexPaths:withRowAnimation: crashes my app
- iOS调用reloadRowsAtIndexPaths Crash报异常NSInternalInconsistencyException
- iOS调用reloadRowsAtIndexPaths Crash报异常NSInternalInconsistencyException
- iOS Crash之NSInternalInconsistencyException
- IOS 'NSInternalInconsistencyException'
- 自己新建xib文件后报NSInternalInconsistencyException异常
- ios的crash异常
- deleteRowsAtIndexPaths的NSInternalInconsistencyException异常
- iOS 用StackView的第三方FDStackView,有时会出现crash,'NSInternalInconsistencyException', reason: 'Multiplier is
- ios各种异常crash总结
- 未捕获的异常 'NSInternalInconsistencyException'
- Crash加载ramdump报cpu_possible_mask异常问题
- iOS程序异常crash捕获与拦截
- [IOS]程序异常crash捕获与拦截
- IOS程序异常crash捕获与拦截
- IOS程序异常crash捕获与拦截
- IOS程序异常crash捕获与拦截
- IOS程序异常crash捕获与拦截
- iOS crash捕获异常崩溃日志
- 时间操作
- 获取 view 所在的ViewController
- 生成RGW的火焰图
- linux使用实战--服务器篇
- error: Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCom
- iOS调用reloadRowsAtIndexPaths Crash报异常NSInternalInconsistencyException
- android 添加新的页面(新的activity)
- 隐藏 LoadLibrary() 函数
- Consul入门04 - Consul集群
- angular 插件angular-hint
- c#中高效的excel导入sqlserver的方法
- iOS修改状态栏颜色(无代码)
- rootfs 挂载及启动
- 关于如何controller层的构造