How to push VC from child VC?

59 views Asked by At

I have three UIViewControllers. First one is MainViewController. MainViewController has TabView and, under TabView, childView (UIView). Depending on picked tab, childViewController is opened (on childView). childViewController has TableView. I want to enable when you pick cell on that TableView, to push new UIViewController (let's call it EventDetailViewController) and to be visible on full screen using UINavigationController (without TabView from MainViewController). How to achieve that? I use SnapKit, so everything is programatically.

2

There are 2 answers

0
Raluca Toadere On

You can set the hidesBottomBarWhenPushed property of your detail view controller to true. Here is a short blogpost on this topic.

2
Furkan Sandal On

Instantiate UITabBarController with UINavigationController. Then, push it to the navigationController that Tabbar belongs to. This way, you can push the tabbar and there is no need for a present.

If you are using a storyboard, you can embed the UITabBarController in a UINavigationController for the tabbar.

Example:

final class TabBarController: UITabBarController {

override func viewDidLoad() {
    super.viewDidLoad()

    let firstViewController = UIViewController()
    let secondViewController = UIViewController()
    
    firstViewController.title = "First"
    secondViewController.title = "Second"
    
    let navigationController = UINavigationController(rootViewController: self)
    
    self.viewControllers = [firstViewController, secondViewController]
    
    UIApplication.shared.windows.first?.rootViewController = navigationController
    UIApplication.shared.windows.first?.makeKeyAndVisible()
    
    // Push to Navigation Controller
    let thirdViewController = UIViewController()
    thirdViewController.title = "Third"
    navigationController.pushViewController(thirdViewController, animated: true)
}
}