gpt4 book ai didi

ios - collectionView didSelectItemAt indexPath 未调用 swift

转载 作者:搜寻专家 更新时间:2023-10-31 08:07:58 25 4
gpt4 key购买 nike

我有一个自定义 View ,其中包含如下所示的 Collection View 集。

func setupCollectionView() {
let layout = UICollectionViewFlowLayout()
layout.sectionInset = UIEdgeInsets(top: scaled(height: 15), left: scaled(width: 35), bottom: scaled(height: 15), right: scaled(width: 35))
layout.itemSize = CGSize(width: scaled(width: 30), height: scaled(width: 30))
layout.minimumLineSpacing = 15
layout.minimumInteritemSpacing = 30
collectionView = UICollectionView(frame: CGRect.zero, collectionViewLayout: layout)
collectionView.showsVerticalScrollIndicator = false
collectionView.showsHorizontalScrollIndicator = false
collectionView.register(THTexasHoldemEmojiCell.self, forCellWithReuseIdentifier: THTexasHoldemEmojiCell.className)
}

和委托(delegate)函数

extension THTexasHoldemEmojisView {

func setupDelegates() {
collectionView.dataSource = self
collectionView.delegate = self
}

}

extension THTexasHoldemEmojisView: UICollectionViewDelegate {

func collectionView(_ collectionView: UICollectionView, didHighlightItemAt indexPath: IndexPath) {
print("did highlight item")
}

func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
print("did select item")

}

}

奇怪的是 didHighlightItem 函数可以被调用,但 didSelectItem 不会。我在这里错过了什么吗?感谢您的帮助。

我的 View 连接是 UIViewController(THController) 持有 UIView(THEmojisView),THEmojisView 持有 Collection View 。在 THController 中,我有很多 View 和操作,但不包括 THEmojisView。THController 的 touchesBegan(_ touches: Set, with event: UIEvent?) 是否有可能影响 Collection View 的委托(delegate)函数?

最佳答案

也许您的 Cell 中有一个 subview,其 isUserInteractionEnabledtrue

尝试将 Cell subview 的 isUserInteractionEnabled 属性更改为 false

这对我有用。

关于ios - collectionView didSelectItemAt indexPath 未调用 swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41378891/

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