【问题标题】:UICollectionViewCell Only Updates After ScrollingUICollectionViewCell 仅在滚动后更新
【发布时间】:2015-05-08 12:26:34
【问题描述】:

我的 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;
}

【问题讨论】:

  • 你的arrayOfStrings在哪里分配和获取数据?

标签: ios objective-c uicollectionview uicollectionviewcell


【解决方案1】:

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

您应该在 viewDidLoad 方法中执行的操作只需调用 [collectionview reloadData]; 就可以了

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多