swift - 将 ViewController 添加到 UICollectionviewcell
问题描述
我想在 UICollectionView 单元格中嵌入一个 ViewController,我试图在互联网上搜索,但我没有找到任何适用于我的案例的东西。
到目前为止,我已经这样做了,
这是视图控制器:
class ExploreViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .systemGreen
}
}
这是 collectionViewCell:
class ExploreCollectionViewCell: UICollectionViewCell {
let exploreViewController = ExploreViewController()
override init(frame: CGRect) {
super.init(frame: frame)
addSubview(exploreViewController.view)
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
基本上我在单元格内实例化一个 ViewController 并显示它的视图;
我不认为这实际上是最好的事情,但老实说,我不知道如何以不同的方式实现它。
最好的办法是将 viewController 实际嵌入到单元格中,你知道我该怎么做吗?
解决方案
推荐阅读
- r - 按行和名称将单个向量元素分配给单个列 - r
- jquery - 使用 jQuery 对嵌套的剑道甜甜圈图进行爆炸和标注
- azure - 连接到 LDAP 服务器时出错 - jFrog Artifactory 与 Azure LDAPS 集成
- javascript - 当我使用 jquery AJAX 函数将参数解析为 asp.net 代码时调用的错误函数
- python - Python 使用代理
- wix - 在 WiXSharp 中创建动态安装目录
- javascript - 无法在 Chrome 网络选项卡中看到 1000 万字符长度的请求有效负载
- ios - 支持的方向与应用程序没有共同的方向,并且 [RCTModalHostViewController shouldAutorotate] 返回 YES
- c++ - 使用共享指针的函数调用,其对象应为 const
- node.js - 在 Python3 中使用 base64.urlsafe_b64decode 时,我们得到数据“字节”作为数据类型。而在 NodeJS 中,我们得到 Buffer