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

本文是集合了大神们的解答,仅用于自己的记载和查看

运行

[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 换一下方法就好了

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值