Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

iOS

How does Navigation Controller work with Split View Controller under the hood?

I have difficulty understanding the behavior on iPhone(Portrait).

Several cases:

No navigation controller for both master and detail, it shows master in the beginning. If master is embedded in a navigation controller, then it shows detail first, yet you can go back to master through navigation bar.

Question: Master is the only one embedded in navigation controller, isn't it supposed to be the only controller on navigation stack? How does detail get a navigation bar and pop-off effect like it is on that stack as well?

If I go the other way around, put a navigation controller in Detail instead of Master. Not surprisingly, it shows Master first this time. Yet Master does not get the same treatment, it does not get a navigation bar, and there is no way you can go back from it to Detail.

Question: What causes this different "treatment"?

1 Answer

Steven Deutsch
Steven Deutsch
21,046 Points

Hey Yaxin Yuan,

For portrait mode on the iPhone the UISplitViewController will display the detail view first when the app is displayed on screen. If you want to change which view is displayed first, you can use the UISplitViewControllerDelegate to do so.

If you return true from the UISplitViewControllerDelegate method, splitViewController(_:collapseSecondaryViewController:ontoPrimaryViewController:), your master view, or root view in the navigation controller in your case, will be displayed first.

For more information, check the UISplitViewController documentation: UISplitViewController

UISplitViewControllerDelegate documentation: UISplitViewControllerDelegate

Good Luck