UICollectionViewCell Only Updates After Scrolling

你说的曾经没有我的故事 提交于 2019-12-08 03:33:25

问题


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:


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



来源:https://stackoverflow.com/questions/30123864/uicollectionviewcell-only-updates-after-scrolling

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!