简体   繁体   English

无法在表格视图单元格内滚动集合视图(在情节提要中创建)

[英]Unable to scroll Collection view inside Table view cell (created in Storyboard)

There is a very similar question here , but the solution doesn't solve anything for me, mainly because my embedded collection view is already inside the table view cell's content view (I created it in storyboard). 这里有一个非常相似的问题,但该解决方案并没有为我解决任何问题,主要是因为我的嵌入式集合视图已经在表格视图单元格的内容视图中(我在情节提要中创建了它)。

Is there some setting that I need to check to allow my collection view to scroll?我需要检查一些设置以允许我的收藏视图滚动吗? It seems that the parent table view cell is eating up all gestures.似乎父表视图单元格正在吃掉所有手势。

TableViewController.swift TableViewController.swift

class TableViewController: UIViewController, UITableViewDelegate, UITableViewDataSource, UICollectionViewDataSource, UICollectionViewDelegate {

@IBOutlet weak var tableView: UITableView!

override func viewDidLoad() {
    super.viewDidLoad()
    tableView.delegate = self
    tableView.dataSource = self
}

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return 1
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! CustomTableViewCell
    cell.collectionView.dataSource = self
    cell.collectionView.delegate = self
    return cell
}

func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
    return 5
}

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
    let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "collectionCell", for: indexPath)
    return cell
}

}

CustomTableViewCell.swift CustomTableViewCell.swift

class CustomTableViewCell: UITableViewCell {

@IBOutlet weak var collectionView: UICollectionView!

override func awakeFromNib() {
    super.awakeFromNib()
    // Initialization code
}

override func setSelected(_ selected: Bool, animated: Bool) {
    super.setSelected(selected, animated: animated)

    // Configure the view for the selected state
}

}

You can find my demo project here https://github.com/MattiaPell/CollectionView-inside-a-TableViewCell你可以在这里找到我的演示项目https://github.com/MattiaPell/CollectionView-inside-a-TableViewCell

在我的情况下,这很简单,因为没有为我的子集合视图标记User Interaction Enabled检查。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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