ios – collectionView didSelectItemAt indexPath不叫swift

前端之家收集整理的这篇文章主要介绍了ios – collectionView didSelectItemAt indexPath不叫swift前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个自定义视图,其中包含如下所示的集合视图集.

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)
}

和委托功能

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不会.我错过了什么吗?谢谢你的帮助.

我的视图连接是UIViewController(THController)持有UIView(THEmojisView),THEmojisView持有集合视图.
在THController中我有很多观点和动作,但不包括THEmojisView.
THController的touchesBegan(_ touches:Set,with event:UIEvent?)是否有可能影响集合视图的委托函数

解决方法

THTexasHoldemEmojiCell可能存在问题.也许在集合视图单元格中有一个UIControl实例可以处理所有触摸.简单的解决方案是将此UIControl的isUserInteractionEnabled属性设置为false.

猜你在找的iOS相关文章