我一直試圖讓這個工作超過1個月,不用說,它變得可笑。我無法弄清楚我的方法是否錯誤,或者是否有導致問題的獨特設置。我已經在下面的過程中嘗試了幾十個變體,並取得零成功。將視圖控制器添加到堆棧頂部
我在AppDelegate中有一個過程,它調用委託控制器中的一個函數,該控制器獲取用戶數據以準備顯示其配置文件。
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject], fetchCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void) {
notificationsDelegate.userId = thisid
notificationsDelegate.getUser()
}
在notificationsDelegate中,數據檢索的成功代碼觸發,因此在那裏沒有問題。然後,代碼應該將用戶配置文件視圖添加到堆棧的頂部,以便在應用重新打開時顯示,但不會顯示。正在使用的代碼是
var root = UIApplication.sharedApplication().delegate!.window!?.rootViewController as! UINavigationController
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let pvc = storyboard.instantiateViewControllerWithIdentifier("UserProfile") as! UserProfile
pvc.modalPresentationStyle = UIModalPresentationStyle.FullScreen
pvc.user = user
root.visibleViewController!.presentViewController(pvc, animated: true, completion: nil)
我有這個進程中的一個警告,所以我知道它運行,但應用程序只是重新打開無論它是當不被添加在上面用戶控制器關閉。
這個過程看起來是否正確?
順便說一句,我已經試過
root.presentViewController....
root.pushViewController....
root.topViewController.presentViewController....
root.topViewController.presentedViewController.presentViewController...
添加在呈現一個完成處理程序的顯示,這是沒有得到完成。
也許嘗試將一個鍵值對添加到NSUserDefaults,然後從viewDidLoad將正確的視圖置於頂部,每當應用程序重新打開? –
@ lior感謝您的建議 - 我嘗試過這樣的方法,而且還有問題,可能更容易排除故障 - 主要問題是,我不在乎或不知道什麼視圖是在堆棧頂部時,應用程序重新打開,因爲它應該沒關係,但也許我必須解開用戶沒有任何理由只是爲了確保我在視圖上可以運行提示代碼 – RobertyBob
現在嘗試root.pushViewController ...並沒有好的 – RobertyBob