【问题标题】:How navigate from one view to another without using NavigationController?如何在不使用 NavigationController 的情况下从一个视图导航到另一个视图?
【发布时间】:2017-01-16 04:04:24
【问题描述】:

我想在从 UIViewController 登录后调用 UITabBarController

我使用 pushViewController 但它不起作用。 这是我的代码

    let dashboarController = DashboardTabBarController()
    self.navigationController?.pushViewController(dashboarController, animated: false)
    self.dismiss(animated: true, completion: nil)

这是我在 DashboardController 中的代码

 DashboardTabBarController: UITabBarController, UITabBarControllerDelegate {

override func viewDidLoad() {
    super.viewDidLoad()
    self.delegate = self
    self.view.backgroundColor = UIColor.white

    print("test")
    // Do any additional setup after loading the view.
}

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)

    let tabOne = MerchantTableViewController()
    let tabOneBarItem = UITabBarItem(title: "Merchant", image: UIImage(named: "icon_merchant"), selectedImage: UIImage(named: "icon_merchant"))
    tabOne.tabBarItem = tabOneBarItem

    let tabTwo = RewardsViewController()
    let tabTwoBarItem2 = UITabBarItem(title: "Rewards", image: UIImage(named: "icon_reward"), selectedImage: UIImage(named: "icon_reward"))
    tabTwo.tabBarItem = tabTwoBarItem2

    let tabThree = ViewController()
    let tabTwoBarItem3 = UITabBarItem(title: "Promos", image: UIImage(named: "icon_promos"), selectedImage: UIImage(named: "icon_promos"))
    tabThree.tabBarItem = tabTwoBarItem3

    let tabFour = MerchantTableViewController()
    let tabTwoBarItem4 = UITabBarItem(title: "Transactions", image: UIImage(named: "icon_card"), selectedImage: UIImage(named: "icon_card"))
    tabFour.tabBarItem = tabTwoBarItem4

    let tabFive = ProfileViewController()
    let tabTwoBarItem5 = UITabBarItem(title: "Profile", image: UIImage(named: "icon_profile"), selectedImage: UIImage(named: "icon_profile"))
    tabFive.tabBarItem = tabTwoBarItem5
    self.viewControllers = [tabOne, tabTwo, tabThree, tabFour, tabFive]

   }
}

我是 iOS 开发的新手。谢谢

【问题讨论】:

    标签: ios swift uinavigationcontroller pushviewcontroller uitabcontroller


    【解决方案1】:

    Apple doc says : 导航控制器对象使用导航堆栈管理当前显示的屏幕,该堆栈由视图控制器数组表示。数组中的第一个视图控制器是 根视图控制器。数组中的最后一个视图控制器是当前正在显示的视图控制器。您可以使用 segue 或使用此类的方法从堆栈中添加和删除视图控制器。

    所以现在,如果您不想使用UINavigationController 并添加UIViewController,请按照以下方法:

    1. Present ViewController
    2. Add as a Child VC

    【讨论】:

      【解决方案2】:
      • 您应该让您从中导航的视图控制器在导航中。如果不是,则创建一个具有根的导航视图控制器对象,将源视图控制器作为根视图控制器。

      如果你不想使用导航控制器,那么你可以使用 PresentViewController 方法来呈现视图控制器。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-08-28
        • 1970-01-01
        • 1970-01-01
        • 2013-08-08
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多