我正在使用成功向用户显示登录名的应用程序,将成功登录的用户登录到仪表板上。其中显示了4个标签以导航到各自的用途。我必须使用UITabBarController
来显示四个选项卡,并使用UINavigationController
来从LoginView导航。
当用户成功登录时,我将UITabBarController设置为navigationController。每个视图都有一个注销按钮,单击时,我必须将navigationcontroller
设置回根。
这里是我完成的代码示例。
我的UITabBarController
class TabBarVC:UITabBarController {
let dashboardViewObj = DashboardVC()
let registerViewObj = RegisterVC()
let alertViewObj = AlertVC()
let historyViewObj = HistoryVC()
override func viewDidLoad() {
super.viewDidLoad()
self.viewControllers = [dashboardViewObj, registerViewObj,historyViewObj,alertViewObj]
// Do any additional setup after loading the view.
dashboardViewObj.tabBarItem = UITabBarItem(tabBarSystemItem: .search, tag: 0)
registerViewObj.tabBarItem = UITabBarItem(tabBarSystemItem: .history, tag: 0)
historyViewObj.tabBarItem = UITabBarItem(tabBarSystemItem: .contacts, tag: 0)
alertViewObj.tabBarItem = UITabBarItem(tabBarSystemItem: .bookmarks, tag: 0)
}
在我的LoginViewContoller中
let tabbarObj = TabBarVC()
@IBAction func loginBtnClicked(_ sender: Any) {
self.navigationController?.setViewControllers([tabbarObj], animated: true)
}
现在从这些视图中的任何一个单击注销按钮,我需要将navigationController设置为root。怎么做...?
下面的图表将有助于了解我的需求。任何帮助将不胜感激。
您可以轻松地使用展开命令,而不用设置根视图控制器或弹出视图控制器,甚至关闭方法!参见this for full description