Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing Detail's Navigation Bar in UISplitViewController in Portrait mode

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?

like image 908
Candost Avatar asked Aug 17 '16 11:08

Candost


1 Answers

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
like image 56
Ely Avatar answered Oct 17 '22 02:10

Ely