1
有沒有一種方法可以確定當用戶點擊主頁按鈕和應用程序委託功能時活動的ViewController applicationDidEnterBackground函數被調用?Swift:在調用applicationDidEnterBackground時確定活動視圖控制器
有沒有一種方法可以確定當用戶點擊主頁按鈕和應用程序委託功能時活動的ViewController applicationDidEnterBackground函數被調用?Swift:在調用applicationDidEnterBackground時確定活動視圖控制器
所以這行:
let vc: UIViewController = self.window!.rootViewController!
會給你斯威夫特(假設你使用該行裏面的AppDelegate一些方法)的根視圖控制器,但如果你有容器(如的UITabBarController) - 您可能需要繼續進行額外的檢查/檢查...
看看這裏:http://stackoverflow.com/questions/24825123/get-the-current-view-controller-from-the- app-delegate – ppalancica
Objective-C對我來說不是很好,但我會盡力把這篇文章翻譯成Swift。 :) – GED125