Search code examples
iosuiviewcontrolleruinavigationbaruinavigationcontroller

Start second view controller of navigation stack first


There is a default calendar app.

It starts with the next view controller and back button is already there like there some other view controller was started before this one:

enter image description here

When you press back button you get the next view controller:

enter image description here

How did they do it?

In my app I need the same logic (to start a view controller with the latest or default category but users can press back button to select a different category)


Solution

  • If I were to do this, I would start by simply using pushViewController(animated:) to push the month view onto the navigation stack, with animated: false in the root view controller's viewWillAppear(animated:) method. The calendar would appear to the user already one level deep in the navigation stack.

    So, the first controller is the year view, and then the month view is the second one pushed onto the stack, but it all happens before the user has seen any of the views. Simple, right?

    Here are the docs for UINavigationController in case that helps.