ios - UICollectionView 静态 CustomCell 复用

标签 ios objective-c iphone uicollectionview uicollectionviewcell

我在使用自定义单元格创建 UICollectionView 以显示项目时遇到问题。但是在 UICollectionView 刷新后,可重用的单元格填充了错误的索引

刷新前的 UICollectionView。

enter image description here

刷新后的 UICollectionView。

enter image description here

可重用 Collection View 单元格的代码示例。

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{

    GalleryCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];

    if (indexPath.item != 0)
    {
        [cell setCollectionItem:[collectionData_ objectAtIndex:indexPath.row - 1]];
    }

    return cell;

}

最佳答案

认为它正在重用另一个单元格(在本例中为气球)并且没有为第一个索引单元格设置任何内容。如果您使用 else 语句来创建新的相机单元格,希望它会重新出现。

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    GalleryCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];

    if (indexPath.item != 0) {
        [cell setCollectionItem:[collectionData_ objectAtIndex:indexPath.row - 1]];
    } else {
        // Set camera item here
    }
    return cell;
}

关于ios - UICollectionView 静态 CustomCell 复用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29434799/

相关文章:

ios - 使用按钮更改图像位置

ios - 任何使用 Java 脚本的 iPhone UI 自动化教程?

ios - 如何检测 UIWebView 上的 DOM 加载事件?

iphone - 如何使用 Flash 为 iphone 5 优化我的 AIR iOS 应用程序

iphone - 作为获取谓词的日期范围 - Core Data 之间的 NSDate 谓词

ios - Swift 3 Google Map 和 MapKit API - 如果用户当前位置已更新

objective-c - 如何禁用 UITextView 上的键盘?

objective-c - 创建编程语言问题

ios - Base SDK 6.1 在 Xcode 6.0.1 中不显示 iOS 8 模拟器

ios - sortedArrayUsingComparator 不适用于 IOS 中的数组?