我将如何在 UICollectionView 单元格中插入 UIViewController?
最佳答案
您需要创建一个自定义容器 View Controller :https://developer.apple.com/library/content/featuredarticles/ViewControllerPGforiPhoneOS/ImplementingaContainerViewController.html
func display(contentController content: UIViewController, on view: UIView) {
self.addChildViewController(content)
content.view.frame = view.bounds
view.addSubview(content.view)
content.didMove(toParentViewController: self)
}
对于容器中的每个单元格,您必须在单元格的内容 View 上使用正确的 subview Controller 调用类似上述函数。
注意不要尝试将多个 View Controller 添加到同一个单元格中,并确保它们也被正确删除。
这个想法非常复杂,不利于简单的堆栈溢出答案,但希望以上内容足以让您入门。
关于ios - 在 UICollectionView 单元格中添加 UIViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42498129/