UICollectionViewCell 仅在滚动后更新 [英] UICollectionViewCell Only Updates After Scrolling

查看:29
本文介绍了UICollectionViewCell 仅在滚动后更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 UICollectionView 有问题,我的单元格总是以空白/默认状态启动,没有数据.

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.

代码:

-(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 数据源调用在此之前完成.

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.

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

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

这篇关于UICollectionViewCell 仅在滚动后更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆