UICollectionViewCell Only Updates After Scrolling

2019-05-30 15:17发布

I've got an issue with my UICollectionView where my cells are always initiated blank/in a default state with no data.

The data only appears in the cells after scrolling them in and out of view.

Thoughts? Thanks.

CODE:

-(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;
}

1条回答
神经病院院长
2楼-- · 2019-05-30 15:22

Your problem is that you probably set the arrayOfStrings somewhere in the viewDidLoad method of your view controller, the problem with that is that the collectionview datasource calls are done before that.

What you should do in your viewDidLoad method just call [collectionview reloadData]; an you will be fine

查看更多
登录 后发表回答