我感到困惑,因为这只是一件简单的事情,但它不起作用。
在写问题之前,这是我的检查清单:
已注册UICollectionViewDelegate
"Debug View Hierarchy"中,UICollectionView上面没有其他视图
UICollectionView和UICollectionViewCell的
isUserInteractionEnabled
属性均为true
UICollectionView的
isAllowsSelection
属性为true
还有什么其他需要我检查的吗?
=====
class MyView: NibDesignable { // It's UIView with NibDesignableProtocol (https://github.com/mbogh/NibDesignable)
@IBOutlet weak var collectionView: UICollectionView!
override init(frame: CGRect) {
super.init(frame: frame)
self.setup()
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
self.setup()
}
private func setup() {
print("test - It's called.")
self.collectionView.dataSource = self
self.collectionView.delegate = self
self.collectionView.isUserInteractionEnabled = true
self.collectionView.isAllowsSelection = true
}
}
extension MyView: UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout {
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath {
print("test - It's not called")
}
}
我只复制了与问题相关的部分,因为所有代码太长了。
我 pasted 只有与 question 相关的部分,因为所有 code 太长了。
UICollectionViewDelegate
吗?例如:class ViewController: UIViewController, UICollectionViewDelegate
。 - Inder Kumar Rathore