使用collectionView 嵌套 collectionView 刷新遇到的坑

[collectionView reloadSections:[NSIndexSet indexSetWithIndex:0]];
[collectionView reloadSections:[NSIndexSet indexSetWithIndex:1]];
[collectionView reloadSections:[NSIndexSet indexSetWithIndex:2]];
[collectionView reloadSections:[NSIndexSet indexSetWithIndex:3]];
[collectionView reloadSections:[NSIndexSet indexSetWithIndex:4]];
[collectionView reloadSections:[NSIndexSet indexSetWithIndex:5]];

当collectionView 分段刷新的时候,部分section contentSize有占用位置 而section却消失不见了



是因为在使用reloadSection的时候 需要保证当前的layout不变;
只需要对最外层的collectionView的cell返回的size修改就可以了
CGSizeZero 替换为
return CGSizeMake(375,0.01f);
有实际大小的一个cell

-(CGSize)collectionView:(UICollectionView *)collectionView layout:(nonnull UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(nonnull NSIndexPath *)indexPath
{
    switch (indexPath.section) {
        case 0:{
            //return CGSizeZero;
            return CGSizeMake(375, 0.01f);
            break;
        }
        case 1:{
            //return CGSizeZero;
            return CGSizeMake(375, 0.01f);
            break;
        }
            
        default:
            return CGSizeZero;
            break;
    }
}
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容