jay patel
jay patel

Reputation: 258

How to call tab bar view controller from simple view controller which is embedded in navigation controller?

How can I call TabbarViewControllers connected viewController from simple UIViewController where simple UIViewController is embedded in UINavigationController. I want same Push and Pop effect which UINavigationController provide when moving one to other viewController. After digging in google I find out that pushing tab bar view controller inside navigation stack is not a good way to structure app. I tried creating custom transaction animation but it's not same like UINavigation transaction effect. Please give some suggestion or solution. Thanks!!

Upvotes: 0

Views: 1375

Answers (2)

imaduddinaf
imaduddinaf

Reputation: 21

as Nirmalsinh's answer, you could set view controller that conform UITabBarControllerDelegate as your self.window.rootViewController, then should have UITabBarController inside it.

var tabBarController: UITabBarController

then you can each of tab's navigation and view controller

let firstViewController = FirstViewController()
let firstNavigationController = UINavigationController(rootViewController: firstViewController)
// other setter

tabBarController.viewControllers = [
    firstNavigationController
]

then inside FirstViewController, you can call

let secondViewController = SecondViewController()
navigationController?.pushViewController(SecondViewController, animated: true)

Upvotes: 0

Nirmalsinh Rathod
Nirmalsinh Rathod

Reputation: 5186

You can directly set UITabbarController to window's rootViewController.

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
_tabObj = (TabbarViewController*) [storyboard instantiateViewControllerWithIdentifier:@"TabbarViewController"];
self.window.rootViewController = _tabObj;

Check above code.

Upvotes: 1

Related Questions