将var从类传递给ViewController

时间:2017-09-16 10:54:33

标签: ios swift xcode

[![在此输入图像描述] [1]] [1]我想将var postKey值改为另一个名为:ExtraViewController的ViewController。第一个var postKey的值需要放在ExtraViewController的var postKey中。这就是我到目前为止所做的。

var postKey = Database.database().reference().childByAutoId().key

        let ExtraViewController = storyboard?.instantiateViewControllerWithIdentifier("ExtraViewController") as! ExtraViewController

        ExtraViewController.postKey = postKey
  

错误:使用未解析的标识符' storyboard'错误:预期   声明

2 个答案:

答案 0 :(得分:0)

无法创建对象,其名称与任何类ExtraViewController匹配

替换您的代码

    let ExtraViewController = self.storyboard?.instantiateViewControllerWithIdentifier("ExtraViewController") as! ExtraViewController

    ExtraViewController.postKey = postKey

使用

    let extraViewController = self.storyboard?.instantiateViewControllerWithIdentifier("ExtraViewController") as! ExtraViewController

    extraViewController.postKey = postKey

答案 1 :(得分:-1)

Use this code-

func moveToOtherView()
{
    var postKey = Database.database().reference().childByAutoId().key
    let storyboard = UIStoryboard(name: "Main", bundle: nil)
    let extraViewController = storyboard?.instantiateViewControllerWithIdentifier("ExtraViewController") as! ExtraViewController
    extraViewController.postKey = postKey
}