[英]Delegate Methods of UICollectionView insider UITableView not called
我有一個UITableView
,其中一個包含UICollectionView
的單元格。
我已經將UITableViewCell
設置為UICollectionView
的委托和數據源,並且在這里我實現了我需要的所有方法。
問題是,這就像我的UICollectionView
不響應觸摸事件:滾動或觸摸工作也不響應。
因此,永遠不會調用collectionView(_:didSelectItemAt:indexPath)
。
UserInteractionIsEnabled
設置為TRUE可以:
1. TableView
2. TableViewCell
3. ContentView
4. CollectionView
5. CollectionViewCell
我真的不知道我的代碼有什么問題。
這是TableViewCell的代碼
import UIKit
class InsertSecondCell: UITableViewCell, UICollectionViewDelegate, UICollectionViewDataSource {
let COUNT = 12
@IBOutlet weak var collectionView: UICollectionView!
override func awakeFromNib() {
super.awakeFromNib()
collectionView.isPagingEnabled = true
collectionView.delegate = self
collectionView.dataSource = self
collectionView.isScrollEnabled = true
collectionView.isUserInteractionEnabled = true
collectionView.reloadData()
}
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
func collectionView(_ collectionView: UICollectionView,
numberOfItemsInSection section: Int) -> Int {
return COUNT
}
func collectionView(_ collectionView: UICollectionView,
cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "categoryCell",
for: indexPath) as! CategoryCollectionCell
cell.allergenImageView.image = UIImage(named: "IMAGE")
cell.titleLabel.text = "TITLE"
cell.bottomViewm.isHidden = false
cell.backgroundColor = UIColor.white
cell.layer.borderColor = UIColor.black.cgColor
cell.layer.borderWidth = 0.5
cell.layer.cornerRadius = 2.5
return cell
}
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
print("hi")
}
}
對於滾動,在IB中是否有彈跳和垂直/水平彈跳?
至於選擇,如果您長按該單元格,它最終是否會打印您的消息? 您可以添加tapGestureRecognizer.cancelsTouchesInView = false
以幫助手勢識別器更快地超越視圖層次結構。 看這里 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.