ios - UICollectionView 单元格在重新加载数据后保持突出显示

标签 ios objective-c uicollectionview reloaddata

我有一个 UICollectionView,其单元格内的标签会定期自动更改。当此更新触发时,我在 UICollectionView 上调用 reloadData 并且我已将单元格设置为更改 [UICollectionViewCell setHighlighted:].

上的背景颜色

问题是如果用户按住一个单元格然后更新发生,当用户释放单元格保持高亮并且不能再被选中。

我注意到 dequeueReusableCellWithReuseIdentifier:forIndexPath: 在 reloadData 之后对单元格调用 setHighlighted。

我还尝试了 reloadSections: 而不是 reloadData,这解决了单元格“卡住”的问题,但在调用时会导致单元格淡出和淡入。

将调用放在 performBatchUpdates: 中似乎也无法解决问题。

最佳答案

在单元格的类中尝试调用:

- (void)prepareForReuse {
    [super prepareForReuse];
    [self setHighlighted:NO];
    ... Any other custom stuff that should be cleaned up ...
}

问题是您对背景着色的处理方式可能与单元格在突出显示时通常自行处理的方式不同。通常,单元格的父类(super class)会撤消 prepareForReuse 中的这些更改,但它不知道您的更改。

关于ios - UICollectionView 单元格在重新加载数据后保持突出显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16730828/

相关文章:

IOS Collection View 布局问题

ios - 单击按钮移动 Collection View (快速)

ios - instagram api获得所有喜欢的计数

ios - cell.detailTextLabel.text 为 NULL

ios - 在 Objective-C 中使用 Swift 字符串调用方法

IOS 10 UIImagePickerController 委托(delegate)未被调用

iphone - 将点从图像转换为 UIImageView 点,contentMode-aware

ios - 弹出到上一个 View 的问题(导航 Controller )

ios - 在 iOS 应用程序中获取所有选定的辅助功能选项

ios - 如何创建 pinterest 布局?