Assertion Failure in UICollectionViewData validateLayoutInRect on ios7

后端 未结 8 1236
误落风尘
误落风尘 2021-02-12 12:51

Assertion Failure in UICollectionViewData validateLayoutInRect on iOS7.

I am trying to delete all UICollectionView items, one by o

8条回答
  •  天涯浪人
    2021-02-12 13:11

    I actually got this crash one time not because I was returning zero for a number of sections or items in a section but because I was reusing a flow layout like this for more than 1 collection view:

    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
    [flowLayout setScrollDirection:UICollectionViewScrollDirectionHorizontal];
    Collection1 = [[UICollectionView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, 50.0f) collectionViewLayout:flowLayout];
    [Collection1 setDataSource:self];
    [Collection1 setDelegate:self];
    [self.view addSubview:Collection1];
    
    Collection2 = [[UICollectionView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, self.view.frame.size.height) collectionViewLayout:flowLayout];
    Collection2.backgroundColor = [UIColor whiteColor];
    

    Instead if I create a new flow layout for each UICollectionView I avoid this crash. Hopefully that might help someone

    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
    [flowLayout setScrollDirection:UICollectionViewScrollDirectionHorizontal];
    Collection1 = [[UICollectionView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, 50.0f) collectionViewLayout:flowLayout];
    [Collection1 setDataSource:self];
    [Collection1 setDelegate:self];
    [self.view Collection1];
    
    UICollectionViewFlowLayout *flowLayoutVert = [[UICollectionViewFlowLayout alloc] init];
    [flowLayoutVert setScrollDirection:UICollectionViewScrollDirectionVertical];
    Collection2 = [[UICollectionView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, self.view.frame.size.height) collectionViewLayout:flowLayoutVert];
    

提交回复
热议问题