简体   繁体   English

一个tableView单元中有两个collectionViews。 collectionViews没有出现

[英]Two collectionViews in one tableView Cell. collectionViews not appearing

I have two different collectionViews inside one table view cell. 我在一个表视图单元格中有两个不同的collectionViews。 Reason is because I am trying to find the best way to implement one horizontal collectionView and a vertical collecitonView that displays different data. 原因是因为我试图找到实现一个水平collectionView和一个显示不同数据的垂直collecitonView的最佳方法。 I just want to get the horizontal collectionView to scroll down with the page when users are scrolling with the vertical collection view. 当用户使用垂直集合视图滚动时,我只想让水平collectionView随页面向下滚动。

I have implemented some code to try to get both collectionViews working inside the table view, however the collection Views are not appearing. 我已经实现了一些代码,试图使两个collectionView在表视图中都可以工作,但是没有出现集合视图。

class PeopleToFollowHeader: UITableViewCell, UICollectionViewDataSource, UICollectionViewDelegate {



    @IBOutlet weak var collectionViewA: UICollectionView!
    @IBOutlet weak var collectionViewB: UICollectionView!    



    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        if collectionView == self.collectionViewA {
            return 6
        } else {
            return posts.count
        }
    }

    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {

        if collectionView == self.collectionViewA {
            let cellA = collectionView.dequeueReusableCell(withReuseIdentifier: "FollowCell", for: indexPath) as! PeopleToFollowCollectionCell
            return cellA
        } else {
            if collectionView == self.collectionViewB {
            let cellB = collectionView.dequeueReusableCell(withReuseIdentifier: "FollowingFeed", for: indexPath) as! FollowingCell
            cellB.posts = posts[indexPath.item]
            return cellB
        }

            return UICollectionViewCell()
    }

    }


    override func awakeFromNib() {
        super.awakeFromNib()
        fetchPosts()
        // Display collectionViews
        collectionViewA.delegate = self
        collectionViewA.dataSource = self
        collectionViewB.delegate = self
        collectionViewB.dataSource = self
        self.addSubview(collectionViewA)
        self.addSubview(collectionViewB)
        collectionViewA.reloadData()
        collectionViewB.reloadData()


    }
    ```

You should reload your collection views after fetchPosts() has returned (assuming it is an asynchronous function). fetchPosts()返回之后(假设它是一个异步函数),您应该重新加载集合视图。

So you should have the data prefetched before reloading the whole tableView is reloaded. 因此,您应该在重新加载整个tableView之前预取数据。

暂无
暂无

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

相关问题 一个View Controller上有两个CollectionViews - Two CollectionViews on one View Controller 如果一个控制器的sizeForItemAtIndexPath中的两个collectionview不起作用 - if two collectionviews in one controller sizeForItemAtIndexPath does not work 如何使用通用协议在 TableView 的第一个和第二个单元格中使用 xibs 添加两个不同的 collectionViews - How to add two different collectionViews with xibs in first and second cell of TableView using common protocol CollectionViews和TableView在StackView中不显示-Swift 4 - CollectionViews and TableView not displaying in StackView - Swift 4 一个 ViewController 中的多个 CollectionViews - Multiple CollectionViews in one ViewController **防止在水平Scrollview中拖动两个CollectionViews ** - **Prevent dragging of Two CollectionViews inside a horizontal Scrollview** 为什么我的UICollectionViewController不能与两个CollectionViews一起运行? - Why will my UICollectionViewController not run with two CollectionViews? 一个 tableView 有两个不同的 cell.xib,如果我按下一个单元格,它需要显示第二个单元格。 如何? - One tableView With two different cell.xib ,If i press one cell it need to show second cell. How? StackView 中的多个 CollectionViews - Multiple CollectionViews In StackView ViewController中有多个UICollectionView 不会调用一个CollectionViews委托方法 - Multiple UICollectionViews in ViewController | Would not call one CollectionViews Delegate methods
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM