2017-09-16 114 views
-2

[![enter]圖像描述] [1]] [1]我想將var postKey值傳遞給名爲ExtraViewController的另一個ViewController。第一個var postKey的值需要放在ExtraViewController的var postKey中。這是我迄今爲止。將var從一個類傳遞到ViewController

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

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

     ExtraViewController.postKey = postKey 

Error: Use of unresolved identifier 'storyboard' Error: Expected declaration

回答

-1

使用此代碼 -

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 
} 
+0

仍然有錯誤.. –

+0

錯誤:使用未解析的標識符「故事板」錯誤:預期聲明 –

+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 
+0

錯誤:無法解析的標識符「故事板」錯誤的使用方法:預計報關 –

+0

@DaniKemper你有相同的兩個故事板視圖控制器? –

+0

不,具有第一個var postKey的ViewController是一個名爲「class Post」的類。 –

相關問題