0
votes

I have two different collectionViews inside one table view cell. Reason is because I am trying to find the best way to implement one horizontal collectionView and a vertical collecitonView that displays different data. I just want to get the horizontal collectionView to scroll down with the page when users are scrolling with the vertical collection view.

I have implemented some code to try to get both collectionViews working inside the table view, however the collection Views are not appearing.

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()


    }
    ```
1
Have you connected the collection views to their outlets in your storyboard? - Brandon Stillitano
@BrandonStillitano Yes - Clint

1 Answers

1
votes

You should reload your collection views after fetchPosts() has returned (assuming it is an asynchronous function).

So you should have the data prefetched before reloading the whole tableView is reloaded.