Swift How to present a tab on a button

In my project, I want to present Tabbar at the click of a button, now I have already created a tab, and I give the identification name "tabbar", which I will show you below.

enter image description here

so now i'm using the below code to call the tab bar controller but i don't get it.

 let tabbar: UITabBarController? = (storyboard.instantiateViewController(withIdentifier: "tabbar") as? UITabBarController)

 navigationController?.pushViewController(tabbar, animated: true)

Can you guys suggest me what I need to do and what code is useful to me to introduce the Tabbar controller.

For more information: I have added an image below that has a blue button in one viewController. I want to introduce a tab bar controller when I click this blue button.

enter image description here

Thank.

+4
source share
5 answers

:
Storyboard Segue: segue .

enter image description here

: self (UIViewController) , .

if let tabbar = (storyboard.instantiateViewController(withIdentifier: "tabbar") as? UITabBarController) {
    self.present(tabbar, animated: true, completion: nil)
}

:

enter image description here

+2

, Apple HIG ( ) , , . , .

, .

, .

, self.navigationController, :

 let tabbar: UITabBarController? = (storyboard.instantiateViewController(withIdentifier: "tabbar") as? UITabBarController)
 print("navigationController = \(navigationController)")
 print("tabbar = \(tabbar)")

 navigationController?.pushViewController(tabbar, animated: true)

navigationController, tabbar nil, .

0

viewController, , " " xcode- > In- > NavigationController.

   let tabbar: UITabBarController? = (self.storyboard?.instantiateViewController(withIdentifier: "tabbar") as? UITabBarController)

    self.navigationController?.pushViewController(tabbar!, animated: true)
0

, , , :

self.present(tabbar, animated: true, completion: nil)
0

, , tabBarController . , .

If so, you can do it.

    let tabBar = self.storyboard?.instantiateViewController(withIdentifier: "tabBar")
   let appDelegate = UIApplication.shared.delegate as! AppDelegate
    appDelegate.window?.rootViewController = tabBar
0
source

Source: https://habr.com/ru/post/1690695/


All Articles