从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/