gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 21:56:00 25 4
gpt4 key购买 nike

我正在使用 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com