从vc10
创建sb.instantiateViewController(withIdentifier:)
,无法使用其property
甚至将其类型转换为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
答案 0 :(得分:1)
您应该在初始化时将其转换为ViewController10
:
var vc10 = sb.instantiateViewController(withIdentifier: "ViewController10") as! ViewController10