2017-09-12 25 views
-2
func presentLoggedInScreen() { 
    let stroyboard:UIStoryboard = UIStoryboard(name: "Main", bundle: nil) 
    let logginedInVCViewController:LogginedInVCViewController = storyboard.instantiateViewController(withIdentifier: "LogginedInVCViewController" as! LogginedInVCViewController, 
    self.present(logginedInVCViewController, animated: true, completion: nil)) 
} 

如何避免此錯誤?用自己的初始值內Swift - 在其初始值內使用的變量

變量

+4

爲什麼','後'as! LogginedInVCViewController'? –

+0

它說要把它或者我得到一個錯誤 – Adeel

+0

使用這個'讓logginedInVCViewController = storyboard.instantiateViewController(withIdentifier:「LogginedInVCViewController」)as! LogginedInVCViewController'並刪除',' – 3stud1ant3

回答

3

試試這個:

func presentLoggedInScreen() { 
    let storyboard = UIStoryboard(name: "Main", bundle: nil) 
    if let logginedInVCViewController = storyboard.instantiateViewController(withIdentifier: "LogginedInVCViewController") as? LogginedInVCViewController { 
     self.present(logginedInVCViewController, animated: true, completion: nil) 
    } 
} 

編輯: 使用另購的結合和什麼導致你的錯誤是和額外
有時XCode的智能感應不能正常工作,所以嘗試分析p roblem第一次:)

+0

你還應該提到原始代碼有什麼問題,然後給你的解決方案,這將是更有益的讀者 – 3stud1ant3

+0

謝謝!!!!救生員XD – Adeel

+0

這是我的第一篇文章,感謝您的建議,我會保持記住 – Adeel

相關問題