簡體   English   中英

從AppDelegate.swift執行Segue

[英]Performing Segue from AppDelegate.swift

我在收到通知后嘗試執行segue。

這是我的應用程序委托中的內容。

func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {


            let viewController = self.window!.rootViewController!.storyboard!.instantiateViewControllerWithIdentifier("SecondViewController")
            self.window?.rootViewController = viewController


    }

這將我直接帶到我想要的視圖,但是導航欄和標簽欄被隱藏了。 從應用程序委托中,如何從一個視圖切換到另一個視圖? 這樣我就可以從第二種觀點出發,就好像我從第一種觀點出發一樣?

您是否嘗試過:

viewController.performSegueWithIdentifier("my_segue_identifier", sender: nil)

另外,更健壯的方法是從AppDelegate廣播NSNotification,並讓您的視圖控制器監聽特定的通知。

我的解決方案:在AppDelegate中添加公共變量(等標志= 1)

    @available(iOS 10.0, *)
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
    print("User Info = ",response.notification.request.content.userInfo)
    flag = 1;   <---
    completionHandler()
}

並檢查rootviewcontroller-> ViewDidLoad上的標志。 如果是真的? 打電話給你特別的segue

    override func viewDidLoad() {
    super.viewDidLoad()
    if (flag == 1) {
        self.performSegue(withIdentifier: "roottanBildirimSegue", sender: self)
    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM