ios - 在 UICollectionView 单元格中添加 UIViewController

标签 ios swift

我将如何在 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/

相关文章:

ios - CIImage 应该是平等的吗?

ios - 使用回调延迟 swift 服务类的输出

iOS5 使用 webkit-overflow-scrolling 滚动时图像消失 : touch

iphone - Button 离开高亮状态时的调用方法

ios - 如何激活选项卡 IOS

ios - didSelectLinkWithURL 没有被 TTTAttributedLabel 调用

ios - 如何消除导航栏顶部的间隙?

ios - Swift 中标签内的链接

swift - 如何执行条件转场

ios - 如何获取 UIView 当前位置?