gpt4 book ai didi

ios - 在我使用 forin collectionView.visibleCells 将 cell.selected 设置为 NO 后,选择其他它们再次自动选择

转载 作者:行者123 更新时间:2023-11-29 00:22:50 25 4
gpt4 key购买 nike

enter image description here

我的 Collection View 就像上面一样,当选定的单元格全部消失时我正在调用一个 Action :

- (IBAction)clearAction:(UIButton *)sender {

for (CustomCell *cell in self.buy_code_cv.visibleCells) {

if (cell.selected) {
[cell setSelected: NO];
}

}
}

在自定义单元格的 .m 文件中:我覆盖了 setSelected: 方法:

- (void)setSelected:(BOOL)selected {

[super setSelected:selected];

//self.selected = !selected;


if (selected) {
self.backView.backgroundColor = APP_COLOR;
self.number_label.textColor = [UIColor whiteColor];
self.multiple_label.textColor = [UIColor whiteColor];

}
// uncheck
else {

self.backView.backgroundColor = [UIColor whiteColor];
self.number_label.textColor = HexRGB(0x999999);
self.multiple_label.textColor = HexRGB(0xcccccc);
}

if (self.delegate && [self.delegate respondsToSelector:@selector(didSelectedCustomCell:)]) {

[self.delegate didSelectedCustomCell:self];
}

}

如何解决 UICollectionView 中的这个问题?

最佳答案

UICollectionViewCell 只是 Collection View 状态的表示,它不保存 Collection View 的状态。可以选择屏幕外的项目,在这种情况下,该项目甚至不会有 UICollectionViewCell 实例。

您需要告诉 Collection View 取消选择该项目并让它负责更新任何屏幕上的单元格,而不是直接更新单元格。

- (IBAction)clearAction:(UIButton *)sender {

for (NSIndexPath *indexPath in self.buy_code_cv.indexPathForSelectedItems) {

[self.buy_code_cv deselectItemAtIndexPath:indexPath animated:YES];

}
}

关于ios - 在我使用 forin collectionView.visibleCells 将 cell.selected 设置为 NO 后,选择其他它们再次自动选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43882985/

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