推送到navigationController不起作用

时间:2016-04-28 08:46:02

标签: swift uitabbarcontroller swrevealviewcontroller presentviewcontroller

好吧,我完全改变了我之前的代码,这就是我需要的,但是最后一次推送导航控制器无法正常工作

        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)
                }

            })

        }

    }

1 个答案:

答案 0 :(得分:0)

我将新的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)
                                }
                            }

                        }

                    })

                }
            }
        }

    }