Interested in the mechanism of returning to the original TableViewController under the control of UINavigationController .

The point is that there is a main TableViewController with static cells that plays the menu role, and there are also two ViewController - oneVC and twoVC

It is required to make it so that in OneVC when you press a button, twoVC and vice versa. The main snag is that in NavigationBar when you press the "back" button from any controller, return to the main TableViewController , and not to the previous window.

Is it possible to arrange such a transition?

    1 answer 1

    This behavior occurs because you call twoVC using the twoVC method self.present(twoVC, animated: true, completion: nil) - i.e. modally

    To be able to return to previous controllers, you must use the navigationController?.pushViewController(twoVC, animated: true) method which inserts your new controller into the navigation stack.

    Using the UINavigationController methods, you can control the controllers in the stack.

    For example, the navigationController?.viewControllers will return you an array of controllers that are in the navigation stack.

    UPD:

    Override the back button and use the required method.

    func popToRootViewController(animated: Bool) - pop to the main (very first) controller.

    func popToViewController(UIViewController, animated: Bool) - pop on the required controller.

    • So I need to return not to the previous oneVC for example, but to the original TableVC menu - Ivan Kisin
    • and I call the transition through the inspector, not the code - Ivan Kisin
    • @IvanKisin Then you need to look in the direction of Unwind Segue - Vitaly