从app delegate打开控制器

时间:2016-12-28 17:43:23

标签: ios swift swift2

如果使用下面的代码点击推送通知,我试图从app delegate打开一个视图控制器

func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject], fetchCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void) {
        if(application.applicationState==UIApplicationState.Inactive ){
            let sdViewController = mainStoryboardIpad.instantiateViewControllerWithIdentifier("StudentViewController") as! StudentViewController
            let navController = UINavigationController(rootViewController: sdViewController)
            navController.setViewControllers([sdViewController], animated:true)
            self.window?.rootViewController = navController
       }

}

控制器打开,但显示导航的菜单图标不起作用。如何使菜单图标显示侧面导航。

1 个答案:

答案 0 :(得分:0)

试试这个

let rootViewController = self.window!.rootViewController as! UINavigationController
rootViewController.pushViewController(sdViewController, animated: true)