iOS deleteRowsAtIndexPaths报错
来源:互联网 发布:js string length 编辑:程序博客网 时间:2024/06/05 00:29
问题1
今天遇到删除一行的cell报错。我的代码
MyTaskRecordModel *model=sender.object;
NSInteger tem=[_dataArrayindexOfObject:model];
NSLog(@"%ld",(long)tem);
NSIndexPath *indepath=[NSIndexPathindexPathForRow:teminSection:0];
[_dataArrayremoveObject:
indepath];
[self.tableViewdeleteRowsAtIndexPaths:[NSArrayarrayWithObjects:indepath,nil]withRowAnimation:UITableViewRowAnimationTop];
看来看去 么有错啊。先是删除数据,然后再从ui页面中删除。百思不得。
然后没有办法了,看报错的日志把
*** Assertion failure in -[UITableView _endCellAnimationsWithContext:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit/UIKit-3512.30.14/UITableView.m:1720
** 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 (40) must be equal to the number of rows contained in that section before the update (40), 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).'
* *终止应用程序由于异常“NSInternalInconsistencyException”,原因是:“无效的更新:无效0节的行数。包含在一个现有的行数部分更新后(40)必须等于之前部分中包含更新的行数(40),加上或者减去从部分插入或删除的行数(1 0插入、删除)和正负的行数的进入或部分(0搬进来,0搬出去)。
0 进 0 出? ,不能的啊,我已经删除
[_dataArray removeObject:
indepath];。
仔细一看, NSIndexPath *indepath ,不是数据,我操。
应该是 [_dataArrayremoveObject:model];
小细节 浪费了很多时间,改完! 一切ok!
attempt to delete row 1 from section 0 which only contains 1 rows before the update'
我用的block 上错误代码
dispatch_async(dispatch_get_main_queue(), ^{ [self hideHud]; if (!error) { BOOL success=[[dic2 objectForKey:@"success"]boolValue]; if (success ) { NSInteger d=[_dataArray indexOfObject:dic]; [_dataArray removeObject:dic]; [_tableview deleteRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath, nil] withRowAnimation:UITableViewRowAnimationTop]; }else{ [StatusBarConfig showMsg:@"error 错误代码1001"]; } }else{ [StatusBarConfig showMsg:@"error 错误代码1002"]; } });
由于block 的特性。对 indexPath 创建了一个备份,所以删除的时候,找不到对应地方。
解决办法,不用
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {中的 indexPath用自己获得 indexPath
NSInteger d=[_dataArray indexOfObject:dic]; [_dataArray removeObject:dic]; NSIndexPath *path=[NSIndexPath indexPathForItem:d inSection:0]; [_tableview deleteRowsAtIndexPaths:[NSArray arrayWithObjects:path, nil] withRowAnimation:UITableViewRowAnimationTop];
问题解决
- iOS deleteRowsAtIndexPaths报错
- deleteRowsAtIndexPaths
- IOS -- 调用deleteRowsAtIndexPaths:withRowAnimation:崩溃的问题
- iOS开发:UITableView的deleteRowsAtIndexPaths方法的使用
- deleteRowsAtIndexPaths崩溃
- iOS常见报错
- iOS线程报错
- iOS报错汇总
- iOS报错解决方案
- ios --编译报错
- deleteRowsAtIndexPaths的NSInternalInconsistencyException异常
- swift tableView deleteRowsAtIndexPaths
- ios,php推送报错
- iOS objc_msgSend 报错解决方案
- iOS objc_msgSend 报错解决方案
- ios 工程’weak‘报错
- IOS程序编译报错
- iOS objc_msgSend 报错解决方案
- iOS9 HTTP请求失效
- 读取SSDT表和原函数地址
- webView后台播放音乐不能关闭的解决办法
- UIProgressView
- 42134123421
- iOS deleteRowsAtIndexPaths报错
- KindEditor 中文乱码问题
- MXNet 中文文档
- app的启动时间测试
- Android的短信的使用
- 日服巫术online过驱动保护分析(纯工具)(工具+自写驱动)
- 【到处都是以太网】铁路篇:标准化作业进入最终阶段,欧洲和日本扩大采用
- HDU 2066 一个人的旅行(Spfa)
- 转:树莓派 ftp