我一直在寻找在 UICollectionView 单元格中获取 UITableView 的方法,但到目前为止,我只找到了完全相反的内容:TableView 单元格中的 CollectionViews。我的方法如下:
集合视图控制器:
class CollectionViewController: UICollectionViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 5
}
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "collectionViewCell", for: indexPath) as! CollectionViewCell
return cell
}
}
自定义 CollectionViewCell:
class CollectionViewCell: UICollectionViewCell {
override func awakeFromNib() {
super.awakeFromNib()
let tableView = UITableView()
self.contentView.addSubview(tableView)
}
}
目标是在水平滚动的页面中显示信息,并且每个页面可以有很多行(因此在 CollectionViews 中包含 TableViews)。但是,我似乎无法弄清楚如何为每个添加到 CollectionView 单元格的 TableView 实例添加一个 TableViewController。
提前致谢。
不确定这是否真的值得回答......但回到我们的评论讨论......
您可以像任何 UIView 或 UIViewController 一样使 UICollectionView 符合 tableview 协议。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句