gpt4 book ai didi

ios - 如何让 UICollectionView 单元格可以在其 setSelected : method? 中被多选

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:33:10 24 4
gpt4 key购买 nike

这是我的 UICollectionView:

在 Collection Cell 中,有一个 setSelected: 方法,我可以选择单元格的颜色:

- (void)setSelected:(BOOL)selected {

[super setSelected:selected];

//self.selected = !selected;

// checked
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);
}
}

但在我的 tableView 中,如果我点击另一个单元格,所选单元格将被取消选中,因此单元格中只有一个单元格被选中。

那么,如何在 UICollectionView 中多选单元格?

最佳答案

你应该设置allowsMultipleSelection YES:

A Boolean value that determines whether users can select more than one item in the collection view.

This property controls whether multiple items can be selected simultaneously. The default value of this property is false.When the value of this property is true, tapping a cell adds it to the current selection (assuming the delegate permits the cell to be selected). Tapping the cell again removes it from the selection.

关于ios - 如何让 UICollectionView 单元格可以在其 setSelected : method? 中被多选,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43868045/

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