2017-03-03 36 views
0

我正在使用Swift 3,Xcode 8.2。Swift 3 - 實例化視圖控制器後沒有成員錯誤

當我創建一個視圖控制器和嘗試訪問它的變量之一,我得到一個:Value of type 'UIViewController' has no member 'someObjectVar'

這裏是我的代碼:

let testVC = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "testVC") as UIViewController 

testVC.someObjectVar = someObject // error is here 

self.present(testVC, animated: true, completion: nil) 

testVC變量是:

var someObjectVar : someObjectType! 

我發現this question與我有同樣的問題,但解決方案不適合我,因爲我沒有做同樣的事情...

任何幫助將不勝感激。

+1

你實際上和你在鏈接問題中的提問者做的事情是一樣的,他們在評論中提出的解決方案實際上並沒有意義,儘管你需要將'as UIViewController'改爲'as! [實際的testVC類]'而不是僅僅刪除它。 – dan

回答

1

您正在將其轉換爲UIViewController,它絕對沒有該屬性。您需要將其轉換爲您所做的具有與其相關聯的屬性的任何UIViewController子類。

+0

哦,我的天啊。什麼是骨頭錯誤!非常感謝你爲我指出這一點。 – noblerare

相關問題