gpt4 book ai didi

ios - 类型 'UIViewController' 的值没有成员 'addSubview' Swift2

转载 作者:行者123 更新时间:2023-11-28 09:44:25 24 4
gpt4 key购买 nike

我有这个错误:

value of type 'UIViewController' has no member 'addSubview'

在这段代码中。你知道为什么吗?

override func viewDidLoad() {
self.currentViewController = self.storyboard?.instantiateViewControllerWithIdentifier("ComponentA")
self.currentViewController!.view.translatesAutoresizingMaskIntoConstraints = false
self.addChildViewController(self.currentViewController!)
self.addSubview(self.currentViewController?.view, toView: self.containerView)
super.viewDidLoad()

最佳答案

selfUIViewController 的实例。它定义了 viewDidLoad()addChildViewController() 等方法。

addSubview() 方法是在类 UIView 上定义的。如果 View Controller 为其 view 属性设置了一个 View ,您可以通过调用 self.view.addSubview() 来访问它。

关于ios - 类型 'UIViewController' 的值没有成员 'addSubview' Swift2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37573785/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com