简体   繁体   English

如何在不使用 NavigationController 的情况下从一个视图导航到另一个视图?

[英]How navigate from one view to another without using NavigationController?

I want to call the UITabBarController after signing in from a UIViewController我想在从 UIViewController 登录后调用 UITabBarController

I use the pushViewController but it doesn't work.我使用 pushViewController 但它不起作用。 Here's my code这是我的代码

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

This is my code in DashboardController这是我在 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]

   }
}

I'm a newbie in iOS development.我是 iOS 开发的新手。 Thanks谢谢

Apple doc says : A navigation controller object manages the currently displayed screens using the navigation stack , which is represented by an array of view controllers. Apple doc 说:导航控制器对象使用导航堆栈管理当前显示的屏幕,导航堆栈由一组视图控制器表示。 The first view controller in the array is the root view controller .数组中的第一个视图控制器是根视图控制器 The last view controller in the array is the view controller currently being displayed .数组中的最后一个视图控制器是当前显示的视图控制器。 You add and remove view controllers from the stack using segues or using the methods of this class.您可以使用 segues 或使用此类的方法从堆栈中添加和删除视图控制器。

So now , if you don't wanted to you use UINavigationController and add the UIViewController , follow below methods:所以现在,如果您不想使用UINavigationController并添加UIViewController ,请按照以下方法操作:

  1. Present ViewController 当前视图控制器
  2. Add as a Child VC 添加为子 VC
  • You should have the view controller from which you are navigating is in the navigation.您应该将导航的视图控制器放在导航中。 If it is not, then create a navigation view controller's object with root having you source view controller as root view controller.如果不是,则创建一个导航视图控制器的对象,其 root 将您的源视图控制器作为根视图控制器。

If you don't want to use navigation controller then you can use PresentViewController method to present view controller.如果您不想使用导航控制器,那么您可以使用 PresentViewController 方法来呈现视图控制器。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何通过一个导航控制器和另一个导航控制器导航回来? - How to navigate back through one navigationController and another navigationController? 如何从一个视图导航到另一个视图而无需导航? 在iPhone中 - how to navigate from one view to another without navigation? in iphone 使用后退按钮从NavigationController导航到另一个NavigationController - Navigate from NavigationController to another NavigationController with a back button 如何使用 Swift 从一个视图控制器导航到另一个视图控制器 - How to Navigate from one View Controller to another using Swift 使用UIButton从一个视图导航到另一个视图 - Navigate from one view to another using UIButton 如何在不使用情节提要或IB的情况下从嵌入式集合视图的单元导航到另一个视图控制器? - How to navigate from an embedded collection view’s cell to another view controller without using Storyboard or IB? 如何从一个视图控制器导航到另一视图控制器? - How to navigate from one view controller to another view controller? 如何在ios中从一个视图导航到另一个视图? - How to Navigate from one view to another view in ios? 如何通过单击按钮在 Swift UI 中从一个视图导航到另一个视图 - How to navigate from one view to another in Swift UI on a click of button 如何使用SlideMenuViewcontroller从Mainviewcontroller导航到另一个视图控制器 - How to navigate from Mainviewcontroller to another view controller using SlideMenuViewcontroller
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM