如何使用swift 3将数据从viewcontroller A传递到另一个viewcontroller B. [英] How to pass data from viewcontroller A to another viewcontroller B using swift 3

查看:406
本文介绍了如何使用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 through Passing 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.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆