它有一个 replacementView
作为 Storyboard中的 UIView
@IBOutlet var replacementView: UIView!
已连接。
我想用
替换replacementView
replacementView = SecondViewController().view
但它不起作用。有什么问题?
最佳答案
replacementView
仅供引用。您必须更改 View 堆栈中的对象。
您应该保留对 replacementView
父级的引用。接下来从 parentView 中删除 replacementView
并将 SecondViewController().view
添加到 parentView。
我建议您尝试将 SecondViewController().view
添加为 replacementView
并添加填充约束。
你还应该记住 retain SecondViewController,否则它可能会在它出现之前被释放。阅读有关 addChildViewController(childController: UIViewController)
UIViewController 方法的信息。
关于ios - 我如何快速用自定义 View 以编程方式替换 IBOutlet uiview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38830164/