使用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];
}