【发布时间】:2019-05-11 23:25:01
【问题描述】:
我在一个表格视图单元格中有两个不同的 collectionView。原因是因为我试图找到实现一个水平 collectionView 和一个显示不同数据的垂直 collecitonView 的最佳方法。当用户使用垂直集合视图滚动时,我只想让水平集合视图与页面一起向下滚动。
我已经实现了一些代码来尝试让两个collectionViews 在表格视图中工作,但是collectionViews 没有出现。
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()
}
```
【问题讨论】:
-
您是否将集合视图连接到故事板中的它们的出口?
-
@BrandonStillitano 是的
标签: ios swift xcode uitableview uicollectionview