gpt4 book ai didi

ios - Q : create a vc from sb. instantiateViewController(withIdentifier:) 不能在swift中使用它的属性

转载 作者:行者123 更新时间:2023-11-28 16:05:57 30 4
gpt4 key购买 nike

sb.instantiateViewController(withIdentifier:)创建一个vc10,不能使用它的属性甚至将它的类型转换为ViewController10

下面是我的代码:

vc9:

let sb = UIStoryboard.init(name: "Main", bundle: nil)
var vc10 = sb.instantiateViewController(withIdentifier: "ViewController10")

//vc10.delegate = self // there is the error: Value of type 'UIViewController' hs no member 'delegate'
(ViewController10(vc10)).delegate = self // this did not work too

self.navigationController!.pushViewController(vc10, animated: true)

vc10:

var delegate:ViewController9?  // this is the property delegate

最佳答案

当你初始化它时,你应该将它转换为 ViewController10:

var vc10 = sb.instantiateViewController(withIdentifier: "ViewController10") as! ViewController10

关于ios - Q : create a vc from sb. instantiateViewController(withIdentifier:) 不能在swift中使用它的属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40275385/

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