iOS deleteRowsAtIndexPaths报错
2015-12-30 13:56
417 查看
问题1
今天遇到删除一行的cell报错。我的代码
MyTaskRecordModel *model=sender.object;
NSInteger tem=[_dataArrayindexOfObject:model];
NSLog(@"%ld",(long)tem);
NSIndexPath *indepath=[NSIndexPathindexPathForRow:tem
inSection: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!
问题2
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
4000
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
[b]用[/b]自己获得 indexPath
NSInteger d=[_dataArray indexOfObject:dic];
[_dataArray removeObject:dic];
NSIndexPath *path=[NSIndexPath indexPathForItem:d inSection:0];
[_tableview deleteRowsAtIndexPaths:[NSArray arrayWithObjects:path, nil] withRowAnimation:UITableViewRowAnimationTop];
问题解决
今天遇到删除一行的cell报错。我的代码
MyTaskRecordModel *model=sender.object;
NSInteger tem=[_dataArrayindexOfObject:model];
NSLog(@"%ld",(long)tem);
NSIndexPath *indepath=[NSIndexPathindexPathForRow:tem
inSection: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!
问题2
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
4000
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
[b]用[/b]自己获得 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推送
- iOS 获取今天的0点时间和下一天的0点时间
- An iOS7 and iOS8 simple alert
- iOS沙盒机制
- iOS开发学习路线
- iOS AVAudioPlayer AVAudioRecorder 录音和播放
- iOs警告窗口
- iOS AlertView、ActionSheet
- iOS导航条底部与self.view的分界线怎么隐藏 ,取消导航下边的线
- iOS字符串的各种用法(字符串插入、字符串覆盖、字符串截取、分割字符串)
- iOS应用程序的状态及其切换(生命周期)
- iOS归档、反归档
- iOS定时器(NSTimer)
- iOS长按手势(LongPress)
- iOS轻扫手势(Swipe)
- iOS开发之duplicate symbols for architecture x86_64错误
- iOS旋转手势 (Rotation )
- iOS捏合手势(Pinch)
- iOS拖动手势(pan)
- iOS事件:触摸事件.运动事件.远程控制事件