swift - 推送到导航 Controller 不起作用

标签 swift uitabbarcontroller swrevealviewcontroller presentviewcontroller

好吧,我完全改变了以前的代码,这就是我需要的,但是最后推送到导航 Controller 不起作用

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

                        }

                    })

                }
            }
        }

    }

关于swift - 推送到导航 Controller 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36909608/

相关文章:

swift - 将本地 Swift Package 目标添加到现有 Xcode 项目

swift - SKPhysicsBody 避免碰撞 Swift/SpriteKit

ios - 具有多个 Storyboard的 UITabBarController

ios - UITabBarController 在更多导航 Controller 中暂时缺少项目标题和图像

ios - 如何为应用程序的每个 ViewController 添加页脚?

ios - NSUserDefaults.standardUserDefaults().dictionaryForKey() 返回编译错误

ios - 使用 UserDefaults 设置全局变量

ios - 将数据从 ViewController 传递到 TabBarController

ios - SWRevealViewController 传递参数

ios - SWRevealViewController 隐藏后视 Controller