我正在做一个应用程序,它是一个带有标签栏项目(搜索、登录、更多)的标签栏 Controller 应用程序。用户成功登录后,选项卡栏更改为(搜索、帐户、更多),更多中有注销按钮。问题是当单击注销时,它应该加载 SearchViewController
,如果再次在选项卡栏中单击登录,则不会显示相应的登录页面。它显示黑屏。
@IBAction func btnLogOutClicked(_ sender: UIButton)
{
let hm = SearchVC()
let tabOneBarItem = UITabBarItem(title: "Search", image: UIImage(named: "TabHome.png"), selectedImage: UIImage(named: "TabHome.png"))
hm.tabBarItem = tabOneBarItem
let lgn = LoginVC()
let tabOneBarItem1 = UITabBarItem(title: "Login", image: UIImage(named: "tabAcc.png"), selectedImage: UIImage(named: "tabAcc.png"))
lgn.tabBarItem = tabOneBarItem1
let mropt = MoreVC()
mropt.tabBarItem = UITabBarItem(tabBarSystemItem: .more, tag: 2)
let controllers = [hm, lgn, mropt]
self.tabBarController?.viewControllers = controllers
self.tabBarController?.selectedIndex = 0
}
单击“注销”时如何显示标签栏 Controller ,点击标签栏项目应显示相应的 View Controller 。
最佳答案
在给每个 vc 一个 Storyboard标识符之后,你必须像这样加载每个 vc
let hm = storyBoard.instantiateViewController(withIdentifier: "SearchVC") as! SearchVC
这个
let hm = SearchVC()
在以编程方式创建 vc 时使用,这是黑屏的主要原因,因为在没有布局的情况下加载了 vc
关于ios - 单击按钮时加载 Tabbar Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52094983/