ios - 我如何快速用自定义 View 以编程方式替换 IBOutlet uiview

标签 ios swift uiview

它有一个 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/

相关文章:

ios - 如何使用 NSDateFormatter 解析 ISO 8601/RFC 3339 时区?

ios - ASP.NET 到移动设备

iOS:如何为客户订阅自动续订订阅

ios - NSStreamDelegate 没有收到 NSStreamEvent.HasSpaceAvailable :

ios - Swift 2.0 OneSignal .pushNotification

ios - 如何只为 UIView 的左上角和右上角设置 cornerRadius?

ios - 临时测试的代码签名

swift - 将 0x 格式字符串快速解析为字节

ios - Swift - 根据屏幕大小设置 UIView 的大小

objective-c - 为什么我不能复制 AVCapture Session?