iOS:将 UICollectionView 的单元格标记为已显示

标签 ios objective-c xcode uicollectionviewcell

我正在使用 UICollectionViewCell 显示事件列表。

在屏幕上进行比较时,如何将每个单元格(永远)标记为“已读”?

如果我只向下滚动,我可以做到这一点,如果我“玩”滚动(上下移动),停止工作标记为已读“随机”单元格:我认为是由重用引起的的细胞。那么,我该如何解决呢?

详情:
每个单元格都是一个定制的 Nib

NSString* cellName = [[MyCell class] description];
UINib* nib = [UINib nibWithNibName:cellName bundle:[NSBundle mainBundle]];
[self.collectionView registerNib:nib forCellWithReuseIdentifier:name];

并且在 cellForItemAtIndexPath 委托(delegate)中:

- (UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    NSString* name = [[MyCell class] description];
    QVEventWallPostCell *cell = [cv dequeueReusableCellWithReuseIdentifier:name forIndexPath:indexPath];

    if(/* control */) {
       [cell markAsRead];
    } else {
        /* */
    }
... 
}

最佳答案

将 isRead bool 属性添加到用于在每个单元格而不是单元格本身中显示数据的 Event 对象,并在下次显示单元格时检查其值

Event* thisEvent= [self.dataSource objectAtIndex:indexPath.item];
if(!thisEvent.isRead) {
    thisEvent.isRead=YES;
    // whatever function you use to show the cell as unread; in case the cell is reused from a read cell
} 
else {
     // whatever function you use to show the cell as read
}

关于iOS:将 UICollectionView 的单元格标记为已显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26548789/

相关文章:

ios - 32 位 iOS 设备出现 CoreData 错误

ios - findObjectsInBackgroundWithBlock 显示没有结果

ios - 在 UIImagePickerController 中选择图像后的 MBProgressHUD

ios - 带 RESTKIT 的 ESPN iOS API

ios - NSRange block StartRange

swift - 将 Pod 更新到 Firebase 5.4 后出现 Firebase 错误

TeamCity 中的 Xcode 项目运行程序

iphone - iOS:我可以手动将 wifi 网络与地理位置相关联吗?

ios - 翻转 UIImageView 的问题

ios - 为 UIAlertView 创建摇动动画