【发布时间】:2016-06-16 22:24:17
【问题描述】:
使用多个单元格实现 UICollectionView。
当您单击单元格时,我想将 selectedArray 中的值更改为 true。
这是我的代码:
var selectedArray = [Bool](count:201, repeatedValue:false)
func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
let cell = collectionView.cellForItemAtIndexPath(indexPath)
if cell?.selected == true {
selectedArray[indexPath.row] == true
print("\(selectedArray[indexPath.row])")
}
}
我单击的每个单元格的输出都是错误的,因此我知道某些内容未正确链接,但我只是看不到它。
【问题讨论】:
-
NSMutableIndexSet 是一种更适合跟踪选择的数据结构。
标签: ios arrays swift uicollectionview uicollectionviewcell