本文介绍了如何使用swift 3将数据从viewcontroller A传递到另一个viewcontroller B.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 instantiateViewControllerWithIdentifier(标识符:字符串)
函数从ViewControllerA创建ViewControllerB的实例。
I am creating instance of ViewControllerB from ViewControllerA using instantiateViewControllerWithIdentifier(identifier: String)
function.
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中传递的值如何实现这一点。
I want to access value which i have passed in my ViewControllerB how can i achieve this.
我已经通过
链接,但目标c中的答案。
i alredy gone throughPassing Data between View Controllers link but the answers in objective c.
推荐答案
您可以在<$中声明 var
c $ c> VCB viewController并将数据注入此属性
You just can declare a var
in your VCB
viewController and inject data to this property
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)
}
}
这篇关于如何使用swift 3将数据从viewcontroller A传递到另一个viewcontroller B.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!