collectionview reloaddata 刷新失效或者 不走cellforrow刷新cell

本文介绍了防止UICollectionView刷新闪动的三种方法:1) 使用gcd将刷新操作加入到主线程;2) 指定刷新section;3) 结合UIView的performWithoutAnimation避免隐式动画导致的闪烁。同时提到,当tablview的frame尺寸为0时,可能不会调用cellForRowAt,这可能是出于性能考虑的设计。
摘要由CSDN通过智能技术生成

三个方法,
1,


```objectivec
dispatch_async(dispatch_get_main_queue(), ^ {  //加入到主线程,强制执行reload
            [self.collectionView reloadData];
        });

2,

```objectivec

[self.collectionView reloadSections:[NSIndexSet indexSetWithIndex:0]];//指定刷新的section或者cell

3,reloadSections或者reloadData闪动,因为layer有个隐式动画,在下面的方法里面刷新就行了。

[UIView performWithoutAnimation:^{
           [self.collectionView reloadSections:[NSIndexSet indexSetWithIndex:0]];
}];

综上,最保险的方法

    dispatch_async(dispatch_get_main_queue(), ^ {  //加入到主线程,强制执行reload
           [UIView performWithoutAnimation:^{
            [self.collectionView reloadSections:[NSIndexSet indexSetWithIndex:0]];
            }];
        });

顺带提一下tabview有时候不走cellforrow
在tabview的frame宽度或者高度为0的时候,这个时候就不会走cellforrow,或许是因为不想浪费性能所以这样设计,特别是在用monsary布局的时候,很容易出现这种情况

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值