I have a custom view which hold a collection view set like below.
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)
}
and delegate functions
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")
}
}
The weird thing is the didHighlightItem function could get called, but didSelectItem will not. Did I missed something here? Thanks for any help.
My views connection is UIViewController(THController) holds the UIView(THEmojisView), THEmojisView holds the collection view. In the THController i've got a lot of views and actions, but not cover the THEmojisView. Is it possible that touchesBegan(_ touches: Set, with event: UIEvent?) of THController would affect the delegate funcs of the collection view ?
yourCollectionView?.delegate = self
AndyourCollectionView?.dataSource = self
– iDeveloper