*** Assertion failure in -[UITableView _endCellAnimationsWithContext:], /BuildRoot/Library/Caches/co

在刷新tableView时,往往会遇到这样的情况,突然的程序崩溃,让你防不胜防!
我遇到的情况是这样的,首页tableView分为几个区,每个区的行数是固定的,刷新tableView单个区是没问题的,刷新代码如下:

            dispatch_async(dispatch_get_main_queue(), ^{
                NSIndexSet * indexSet = [[NSIndexSet alloc]initWithIndex:2];
                [self.homeTableView reloadSections:indexSet withRowAnimation:UITableViewRowAnimationAutomatic];
            });

如果我两个区一起刷新,就会出现crash。Debug闪退原因如下:

*** Assertion failure in -[UITableView _endCellAnimationsWithContext:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit/UIKit-3599.6.1/UITableView.m:1610

stackoverflow相关问题询问了下,还是找到了原因:

reason: 'Invalid update: invalid number of rows in section 0. The number of rows contained in an existing section after the update (2) must be equal to the number of rows contained in that section before the update (2), plus or minus the number of rows inserted or deleted from that section (1 inserted, 0 deleted) and plus or minus the number of rows moved into or out of that section (0 moved in, 0 moved out).'

大致意思是说你刷新tableView的那个区的行数有变动,应该和你刷新之前的行数一样才行。我的项目需求特殊,每个区的行数固定的,但是我之前写的确实返回行数是根据数组变动的,将之改成固定行数后就不会出现crash。

那么问题来了,如果说我的需求就是要变动删除某行再刷新tableView,这时候行数是不能写死的,那要怎么处理呢?
也简单,查看苹果API你会发现两个方法一个是删除行,一个是删除区,如下:

[_tableView beginUpdates];  
//删除行
[_tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];  
//删除区deleteSections:
[_tableView endUpdates];  
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值