[英]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
,请按照以下方法操作:
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.