代码之家  ›  专栏  ›  技术社区  ›  Kenpachi

登录到选项卡栏控制器后重定向

  •  1
  • Kenpachi  · 技术社区  · 8 年前

      let okAction = UIAlertAction(title: "Ok", style: UIAlertActionStyle.default){ action in
    
                            if let viewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "DashboardViewController") as? DashboardViewController{
    
                                if let navigator = self.navigationController {
                                    navigator.pushViewController(viewController, animated: true)
                                }
                            }
    
    
                        }
    
    
    
                        myAlert.addAction(okAction);
                        OperationQueue.main.addOperation {
                        self.present(myAlert, animated: true, completion: nil)
                        }
    

    一切正常,但现在在我的第一页“DashboardViewController”

    enter image description here

    如果我重定向到第1页,则不考虑选项卡栏控制器,但如果我通过选项卡栏控制器启动项目,则一切正常。所以我的问题是如何在登录后重定向到选项卡栏控制器

    3 回复  |  直到 8 年前
        1
  •  2
  •   Nishant Bhindi    8 年前
    let tabBarVC = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "TabBarVC") as! TabBarVC
        tabBarVC.selectedIndex = //your selected tab index
        navigationController?.pushViewController(tabBarVC, animated: true)
    

    不要重定向dashboardVC使用tabbarVC,然后选择您想要的第一页的tabIndex

        2
  •  1
  •   Aravind A R    8 年前

        let tabBarController = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: tabBarControllerIdentifier)
        if let navigator = self.navigationController {
             navigator.pushViewController(tabBarController, animated: true)
    }
    
        3
  •  0
  •   Shane Shelton    6 年前

    我的处理方式略有不同。

     func transitionToHome() {
    
        let tabBarViewController = UIStoryboard(name: Constants.Storyboard.mainStoryBoard, bundle: nil).instantiateViewController(withIdentifier: Constants.Storyboard.tabBarController) as! UITabBarController
    
          view.window?.rootViewController = tabBarViewController
          view.window?.makeKeyAndVisible()
    
    }
    

    我将tabBarController重新分配为根视图,这样用户就可以返回,而无需再次登录。我还使用常量文件来组织复杂项目的常量。你可以看到我是如何在上面的代码中引用它们的。

    struct Constants {
    
    struct Storyboard {
    
        static let homeViewController = "HomeVC"
    
        static let tabBarController = "HomeTVC"
    
        static let mainStoryBoard = "Main"
    }
    

    }