UICollectionViewCell仅在滚动后更新

问题描述 投票:1回答:1

我的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;
}
ios objective-c uicollectionview uicollectionviewcell
1个回答
2
投票

你的问题是,你可能在单元格中设置了 arrayOfStrings 在...中 viewDidLoad 方法,问题是在这之前,集合视图的数据源调用已经完成。

你应该在你的 viewDidLoad 方法就叫 [collectionview reloadData]; 你会没事的

© www.soinside.com 2019 - 2024. All rights reserved.