0

我在自定义键盘扩展中的 UI 集合视图中有一个包含图像视图的单元格。一切看起来都很好,除了当我尝试在集合视图中选择一个项目时没有任何反应。有什么想法/建议吗?

是的,我已附上代表。

override func viewDidLoad() {
        super.viewDidLoad()
        self.collectionView.delegate = self
        self.collectionView.dataSource = self
        self.collectionView.allowsSelection = true
        self.collectionView.allowsMultipleSelection = false
}

//This works

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = self.collectionView.dequeueReusableCell(withReuseIdentifier: "cell",for: indexPath)
        cell.backgroundColor = #colorLiteral(red: 0, green: 0.4117647059, blue: 0.8509803922, alpha: 1)
        return cell
    }


//This doesnt

    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
        let cell = self.collectionView.dequeueReusableCell(withReuseIdentifier: "cell",for: indexPath)
        cell.backgroundColor = #colorLiteral(red: 1, green: 1, blue: 1, alpha: 1)
    }

有什么想法/建议吗?

编辑:

将我的代码上传到github以获得更好的建议 :)

4

0 回答 0