小编D. *_*nko的帖子

选择另一个单元格时不会触发 didDeselectItemAt indexPath

我正在尝试实现此功能:在我的应用程序中,如果我在 UICollectionView 中选择了一个单元格,则边框变为蓝色,如果我选择另一个单元格,则应取消选择之前的单元格,边框应变为透明。我写了一些方法:

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier, for: indexPath) as! ChatCell

        /* Set some settings */
        if globalSelected[indexPath.item] {
            cell.circleView.layer.borderColor = UIColor.blue.cgColor
        } else {
            cell.circleView.layer.borderColor = UIColor.clear.cgColor
        }

        return cell
}

func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
    //Global variable for maintain selection
    global.selectedChatPath = indexPath
    globalSelected[indexPath.item] = true
    collectionView.reloadData()
}

func collectionView(_ collectionView: UICollectionView, didDeselectItemAt indexPath: IndexPath) {
    if indexPath != nilPath {
        globalSelected[indexPath.item] = false …
Run Code Online (Sandbox Code Playgroud)

ios uicollectionview swift

2
推荐指数
1
解决办法
2226
查看次数

标签 统计

ios ×1

swift ×1

uicollectionview ×1