iOS开发:UITableView的deleteRowsAtIndexPaths方法的使用
2016-07-21 09:56
543 查看
在做一个类似微博的无限长列表的时候,内存的消耗会比较大,常常会触发 didReceiveMemoryWarning 方法,所有有必要在didReceiveMemoryWarning做一些数据释放。
于是删除数据源后 执行[UITableView reloadData]方法,但是此方法会让tableView重新刷新一遍界面,视觉上会有一闪这种影响体验的感觉,于是尝试使用deleteRowsAtIndexPaths方法,使用这个方法容易出现闪退的情况,错误的log如下,原因基本都是因为数据源的删除与删除的cell不匹配导致的,需要仔细检查。
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of rows in section 0. The number of rows contained in an existing section after the update (54) must be
equal to the number of rows contained in that section before the update (110), plus or minus the number of rows inserted or deleted from that section (0 inserted, 54 deleted) and plus or minus the number of rows moved into or out of that section (0 moved in,
0 moved out).'
deleteRowsAtIndexPaths方法注意点:
1.在执行deleteRowsAtIndexPaths方法前,删除dataSource,并确保删除的dataSource与删除的cell严格匹配。
2.追求用户体验的,需要标记当前显示的cell,方便删除多余cell后再重新回到显示之前的位置。
另:deleteRowsAtIndexPaths和reloadData方法的成本哪个更高(据说是第一个更高效,第二个成本更高),没有做深入探究,有兴趣的朋友可以研究研究。
于是删除数据源后 执行[UITableView reloadData]方法,但是此方法会让tableView重新刷新一遍界面,视觉上会有一闪这种影响体验的感觉,于是尝试使用deleteRowsAtIndexPaths方法,使用这个方法容易出现闪退的情况,错误的log如下,原因基本都是因为数据源的删除与删除的cell不匹配导致的,需要仔细检查。
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of rows in section 0. The number of rows contained in an existing section after the update (54) must be
equal to the number of rows contained in that section before the update (110), plus or minus the number of rows inserted or deleted from that section (0 inserted, 54 deleted) and plus or minus the number of rows moved into or out of that section (0 moved in,
0 moved out).'
deleteRowsAtIndexPaths方法注意点:
1.在执行deleteRowsAtIndexPaths方法前,删除dataSource,并确保删除的dataSource与删除的cell严格匹配。
2.追求用户体验的,需要标记当前显示的cell,方便删除多余cell后再重新回到显示之前的位置。
另:deleteRowsAtIndexPaths和reloadData方法的成本哪个更高(据说是第一个更高效,第二个成本更高),没有做深入探究,有兴趣的朋友可以研究研究。
相关文章推荐
- HDG杭州站报名| 分享华为CCE容器云、CloudOpera IES和视频UI开放架构实践
- 设置UIImage的渲染模式:UIImage.renderingMode
- 如何判断字符串是否为GUID格式
- MVC学习系列12---验证系列之Fluent Validation
- GUID与MBR
- Codeforces 689D Friends and Subsequences
- GUID和UUID
- leetcode_376. Wiggle Subsequence(DP 和 Greedy)
- UIView的setNeedsDisplay函数和setNeedsLayout函数的调用情况
- Android Stuido 插件
- setuid()与setgid() -- 设置 UID 和 GID
- setuid()
- easyui-datagrid 编辑模式详解
- 在unigui中为组件添加hint
- UITextField限制输入,几个分类搞定
- POJ 2785 4 Values whose Sum is 0
- AsyncQueryHandler处理数据
- Vue.js——vue-router 60分钟快速入门
- 187. Repeated DNA Sequences
- 375. Guess Number Higher or Lower II