11

I have a UISplitViewController in which MasterViewController and DetailViewController has its own navigation controller.

This is my storyboard:

Current Storyboard for UISplitViewController

When MasterViewController and DetailViewController are both visible (iPhone 6+ Landscape and iPad):

DetailViewController uses Detail Navigation Controller. Everything is perfect in here.

When only DetailViewController is visible (iPhone 6+ Portrait and all other iPhones both Landscape and Portrait):

DetailViewController still uses Detail Navigation Controller (self.navigationController returns Detail Navigation Controller). But on top, Master Navigation Controller's navigation bar is visible, instead of Detail Navigation Controller's navigation bar.

I want to use same navigation bar for DetailViewController for every device size in both portrait and landscape mode. (Styling for master's navigation bar and detail's navigation bar is different.)

Is there a way to do this without declaring a hacky computed property named currentlyVisibleNavigationController or keeping references between ViewControllers?

Candost
  • 1,029
  • 1
  • 12
  • 28
  • 1
    In collapsed mode, a UISplitViewController with a UINavigationController for master appends the detail view controller to the master navigation controller's viewControllers array. When detail view controller is also a navigation controller, it's appended as is, but master's navigation controller look into detail's to present the two as one continuous navigation stack. Master's navigation controller will always take precedence. To style it differently (depending on what styling you're going for) you'd need to make the style of master's nav controller conditional on its top view controller. – Justin Anderson Oct 20 '17 at 15:59
  • Thank you for that explanation @JustinAnderson, that makes sense. – Eugene Nov 23 '18 at 00:02

1 Answers1

2

To get the current UINavigationBar object of the detail controller in a UISplitViewController context, you can try this:

let navigationBar = navigationController?.navigationController?.navigationBar ?? navigationController?.navigationBar
Ely
  • 8,259
  • 1
  • 54
  • 67