I have a UITabBarController which has 4 tabs. I want to show different view controllers for second tab bar item. Depending on the condition I want to show the view controllers for that tab bar item.
I wrote following code :
UITabbarController -
override func tabBar(_ tabBar: UITabBar, didSelect item: UITabBarItem) {
if item.tag == 2 {
if UserDefaults.standard.bool(forKey: "FirstTimeUser") == true {
// let vc1 = storyboard?.instantiateViewController(identifier: "CreateNewProjectViewController") as! CreateNewProjectViewController
// self.navigationController?.pushViewController(vc1, animated: true)
let vc1 = self.storyboard?.instantiateViewController(withIdentifier: "CreateNewProjectViewController") as! CreateNewProjectViewController
let window = UIApplication.shared.windows.first
window?.rootViewController = vc1
tabBarController?.tabBar.isHidden = false
}else {
// let vc2 = storyboard?.instantiateViewController(identifier: "ProjectsViewController") as! ProjectsViewController
// self.navigationController?.pushViewController(vc2, animated: true)
let vc2 = self.storyboard?.instantiateViewController(withIdentifier: "ProjectsViewController") as! ProjectsViewController
let window = UIApplication.shared.windows.first
window?.rootViewController = vc2
tabBarController?.tabBar.isHidden = false
}
}
}
I tried with navigationController but it is showing blank screen.
If I try setting the view controller with "
let vc2 = self.storyboard?.instantiateViewController(withIdentifier: "ProjectsViewController") as! ProjectsViewController
let window = UIApplication.shared.windows.first
window?.rootViewController = vc2
tabBarController?.tabBar.isHidden = false
". It does not show the tab bar, please help me get it correctly. Thank you!
window?.rootViewController = vc1
runs, where is your UITabBarController?