[英]Pass data between TableView and another ViewController in Swift
[英]How to pass data between SplashScreen and ViewController in Swift
當應用程序啟動時,功能檢查是否已連接互聯網。 如果為“是”,則啟動畫面會將有關其的信息傳遞給View Controller。 但是這里我有一個問題,因為SplashScreen和ViewController之間是Navigation Controller。 看起來像這樣:
我使用以下功能從啟動畫面傳遞數據:
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
let VC:ViewController = segue.destinationViewController as! ViewController
VC.connection = isConnection
// connection is a bool var in VievController
}
但是當我決定使用NavigationController Xcode時,向我顯示有關錯誤的信息,例如“無法將'UINavigationController'類型的值(0x1835cec)轉換為'DKTV_Reader.ViewController'(0x23888)”,在以下時間軸顯示我:
let VC:ViewController = segue.destinationViewController as! ViewController
在我使用NAvigationController之前,此解決方案已經非常完美。
您所需的ViewController
嵌入在UINavigationController
,因此從技術上講,它不是destinationViewController
,而是UINavigationController
。 所需的destinationViewController
是導航控制器的第一個視圖控制器,然后可以將其選擇性地轉換為ViewController
類型。
let destination = (segue.destinationViewController as? UINavigationController)?.viewControllers.first as? ViewController
destination?.connection = isConnection
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.