我正在使用instantiateViewControllerWithIdentifier(identifier: String)
函数从ViewControllerA创建ViewControllerB的实例。
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewControllerWithIdentifier("vcB") as VCB;
rootController!.presentViewController(vc, animated: true, completion: nil)
class VCB: UIViewController {
required init?(coder aDecoder: NSCoder){
super.init(coder: aDecoder)
}
}
我想访问我在ViewControllerB中传递的值,我该如何实现这一点。
我已经经历了
Passing Data between View Controllers链接,但目标c中的答案。
最佳答案
您只需在var
viewController中声明一个VCB
并将数据注入该属性
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewControllerWithIdentifier("vcB") as VCB;
vc.yourData = SOME_DATA
rootController!.presentViewController(vc, animated: true, completion: nil)
class VCB: UIViewController {
var yourData: AnyObject?
required init?(coder aDecoder: NSCoder){
super.init(coder: aDecoder)
}
}
关于ios - 如何使用Swift 3将数据从ViewController A传递到另一个ViewController B,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/38888593/