我在我的應用程序中進行漫遊(入門流程),我想要一個跳過按鈕。 該按鈕位於viewController上,所以我想到移動到另一個viewController的最佳方式是訪問應用程序委託窗口。Swift - 從viewController訪問AppDelegate窗口
但是,它讓我錯誤地發現AppDelegate.Type沒有名爲「window」的成員。
@IBAction func skipWalkthrough(sender: AnyObject) {
let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
AppDelegate.window!.rootViewController = RootViewController
}
這種方法有什麼問題嗎?
在此先感謝!
好了吧,有什麼studip錯誤!順便說一句,現在有一個RootViewController的問題,如何訪問此故事板中聲明的視圖控制器?我想創建一個新實例並不是一個好主意?我的意思是RootViewController()導致黑屏,所以應該是另一個等待訪問這樣的控制器 – DCDC
這裏是我如何在我的代碼'let storyboardId =「LoginStoryboardIdentifier」' 'self.window?.rootViewController = self.window? .rootViewController?.storyboard?.instantiateViewControllerWithIdentifier(storyboardId)as? UIViewController' –
完美的工作,但注意到內存消耗,當我用(b)替換根視圖控制器(a)時,我看不到內存減少。 這意味着(a)沒有從記憶中消失,對吧? 如何從內存中擦除它然後顯示(b)控制器 –