UICollectionViewCell仅在滚动后更新

我的UICollectionView出现问题,我的单元格总是空白/处于默认状态而没有数据。

数据仅在滚入和滚出视图后才会出现在单元格中。

思考? 谢谢。

码:

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { static NSString *cellIdentifier = @"EquipmentCell"; APInventoryCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath]; if (!cell) cell = [[APInventoryCollectionViewCell alloc] init]; //set cell data... cell.label.text = [arrayOfStrings objectAtIndex:indexPath.row]; return cell; } 

您的问题是您可能在视图控制器的viewDidLoad方法中的某处设置了arrayOfStrings ,问题是collectionview数据源调用在此之前完成。

你应该在viewDidLoad方法中做什么只需调用[collectionview reloadData]; 你会没事的