iOS Assertion failure in -[UICollectionViewData validateLayoutInRect:]


使用UICollectionView時、滾動過程中發現崩潰報上面的錯誤,

我的使用場景是這樣的在tableviewcell上嵌套tableview1然后在tableview1的tableviewcell上嵌套CollectionView。

collectionView滾動過程崩潰 布局與數據不符 原因是布局的緩存 但同樣的場景tableview就沒有這個問題

  解決辦法:添加以下更新布局的代碼

 

[self.contentView setNeedsLayout];
[self.contentView layoutIfNeeded];

 

 
        
- (void)refreshImg:(NewTaskPointModel *)iCKTrendModel {
    NSInteger count = iCKTrendModel.pictures.count;
    if (count && count<= 9) {
        CGFloat   itemH = 70;
        NSInteger row = (count-1)/3;
        NSInteger collecH = (row + 1) * itemH + row*2;
        
        self.collectionView.hidden = NO;
        self.collectionViewHCons.constant = collecH;
        self.collectionViewWCons.constant = 214;
        self.collectionTopCons.constant = 10;
        
    } else {
        self.collectionView.hidden = YES;
        self.collectionViewHCons.constant = 0;
        self.collectionViewWCons.constant = 0;
        self.collectionTopCons.constant = 0;
    }
    
//    滾動過程崩潰 布局與數據不符 原因是布局的緩存
//    刷新數據
    [self.collectionView reloadData];
//    更新布局
// 立即執行更新
 [self.contentView setNeedsLayout];

  [self.contentView layoutIfNeeded];
 }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM