繁体   English   中英

UICollectionView内部UITableView的委托方法

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM