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