UICollectionView删除cell时崩溃的问题

今天在项目中添加一个UICollectionView的cell上滑动删除的效果的时候遇到下面的崩溃信息。

*** Assertion failure in -[UICollectionView _endItemAnimationsWithInvalidationContext:tentativelyForReordering:], /SourceCache/UIKit/UIKit-3347.44/UICollectionView.m:4072
1、首先是检查删除的方法有没有问题。问了其他开发人员,百度,谷歌了确认删除的方法是没有问题的。
2、再次去谷歌粗暴的百度了一下,还是无果。
3、难道无解,再次仔细看错误信息

*** Assertion failure in -[UICollectionView _endItemAnimationsWithInvalidationContext:tentativelyForReordering:], /SourceCache/UIKit/UIKit-3347.44/UICollectionView.m:4072
2015-05-13 16:23:57.163 SmartHome[463:138180] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of items in section 0.  The number of items contained in an existing section after the update (20) must be equal to the number of items contained in that section before the update (20), plus or minus the number of items inserted or deleted from that section (0 inserted, 1 deleted) and plus or minus the number of items moved into or out of that section (0 moved in, 0 moved out).'
*** First throw call stack:
(0x286c4fef 0x36976c8b 0x286c4ec5 0x293c3f17 0x2c31b42b 0x2c31da8f 0x2c31d8f3 0x2beda667 0x125ae5 0x70d03 0x7075d 0x2be9706b 0x2bd460f9 0x2c15ff9b 0x2bd0f181 0x2bd0d05f 0x2bd444d9 0x2bd43ddd 0x2bd19fe5 0x2bf908fb 0x2bd189f9 0x2868afaf 0x2868a3bf 0x28688a25 0x285d5201 0x285d5013 0x2feb4201 0x2bd79a59 0x116a85 0x36f02aaf)
libc++abi.dylib: terminating with uncaught exception of type NSException
原来是numberOfItemsInSection的返回值写的固定值,在删除了一个cell之后reloadData会触发numberOfRowsInSection,此时返回的cell数量与实际的cell数量已经不一致了,所以导致了数组越界,而崩溃了。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值