create tabbarcontroller on the fly and assign it to the view other than rootview of window

89 Views Asked by At

I want to use a third-party library which implements a nice tabbar controller. But it does all the work programmatically, basically all it does is create two uiviewcontrollers and add them to a tabbarcontroller, and then instantiate an uinavigationcontroller with the tabbarcontroller. In the last step, it assigns the uinavigationcontroller to the rootviewcontroller of the window like the following:

self.window?.rootViewController = getNavigationController()

But I want to use this navigationcontroller in a place other than the rootviewcontroller of the window, say like I want to push from another view and goes to this navigationcontroller. How can I achieve that?

1

There are 1 best solutions below

1
On

You can present it modally over your current navigation controller from your current viewcontroller

let vc = myNavigationControllerWithTabBarControllerInside() //change this to your navigation controller
self.navigationController.presentViewController(vc, animated: true, completion: nil)

Please verify, for your self.navigationController to not be nil. otherwise, use

self.presentViewController(vc, animated: true, completion: nil)