好的,我完全更改了之前的代码,这是我所需要的,但是最后一次推送到导航控制器不起作用

        if application.applicationState == UIApplicationState.Background || application.applicationState == UIApplicationState.Inactive {
        if let user = userInfo["user"] as? String{
            User.loadUserById(user, completion: {result in
                let rootViewController = UIApplication.sharedApplication().keyWindow?.rootViewController as! SWRevealViewController
                let StoryB = UIStoryboard(name: "Main", bundle: nil)
                let Logged : UITabBarController = StoryB.instantiateViewControllerWithIdentifier("TabBarController") as! UITabBarController
                rootViewController.setFrontViewPosition(FrontViewPosition.Left, animated: true)
                let profileViewController : UserProfileVC = StoryB.instantiateViewControllerWithIdentifier("UserProfileVC") as! UserProfileVC
                profileViewController.user = result
                rootViewController.pushFrontViewController(Logged, animated: true)
                let wc = rootViewController.frontViewController as! UITabBarController
                if let wcc = wc.selectedViewController as? UINavigationController{
                    wcc.pushViewController(profileViewController, animated: true)
                }

            })

        }

    }

最佳答案

我将新的tabbarcontroller推入root是错误的,此代码有效

        if application.applicationState == UIApplicationState.Background || application.applicationState == UIApplicationState.Inactive {
       if let type = userInfo["type"] as? String{
            if type == "wink" || type == "met" {
                if let user = userInfo["user"] as? String{
                    User.loadUserById(user, completion: {result in
                        if let rootViewController = UIApplication.sharedApplication().keyWindow?.rootViewController as? SWRevealViewController{

                            let StoryB = UIStoryboard(name: "Main", bundle: nil)
                            rootViewController.setFrontViewPosition(FrontViewPosition.Left, animated: true)
                            let profileViewController : UserProfileVC = StoryB.instantiateViewControllerWithIdentifier("UserProfileVC") as! UserProfileVC
                            profileViewController.user = result
                            if let tabBar = rootViewController.frontViewController as? UITabBarController{
                                if let navigationController = tabBar.selectedViewController as? UINavigationController{
                                    navigationController.pushViewController(profileViewController, animated: true)
                                }
                            }

                        }

                    })

                }
            }
        }

    }

10-02 11:24