您的位置:首页 > 移动开发 > IOS开发

IOS -- 调用deleteRowsAtIndexPaths:withRowAnimation:崩溃的问题

2016-06-16 14:44 453 查看
本文是集合了大神们的解答,仅用于自己的记载和查看

运行

[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationRight];


报错

NSInternalInconsistencyException', reason: 'Invalid update: invalid number of rows in section 0.  The number of rows contained in an existing section after the update (1) must be equal to the number of rows contained in that section before the update (1),


经过无头绪的查询看到了这些个解决方案

一、

[dataArr removeObjectAtIndex:indexPath.section];//这句是肯定要有的
[tableView beginUpdates];
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]  withRowAnimation:UITableViewRowAnimationRight];
[tableView endUpdates];


二、

[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:indexPath.row inSection:0]] withRowAnimation:UITableViewRowAnimationNone];


还是没有解决根本问题 最后的最后

调用deleteRowsAtIndexPaths:withRowAnimation:withRowAnimation:
后如果tableView:numberOfRowsInSection返回的行数不是删除前-1则会crash,同样删除最后一行导致numberOfSectionsInTableView返回值跟调用前不一样而crash。解决方法,调用deleteRowsAtIndexPaths:withRowAnimation:时判断是不是该section最后一行,如果时则同时调用deleteSections:indexSetWithIndex:withRowAnimation:


发现原来我删的是section 换一下方法就好了
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  ios