Search code examples
iosswiftxcodeuitabbarcontrolleruistoryboardsegue

Swift How to present Tabbar on Button click


In my project i want to present Tabbar on button click, now i have already created tabbar and i give identity name as "tabbar" that i show you in below image

enter image description here

so now i am using below code to call Tab bar controller but i am not getting 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 which code is useful to me to present Tabbar controller.

For more specification : i added below image in which there is blue button in one viewController i want to present tab bar controller on click of that blue button

enter image description here

Thank you.


Solution

  • Try this and see:
    Using Storyboard Segue: Connect your segue as present modally with your action button.

    enter image description here

    Programatically: Use self of view controller (UIViewController) and present it modally, like this.

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

    Here is result:

    enter image description here