How to be notified when UISplitViewController pops to master on iPhone mode?

863 Views Asked by At

I am using a UISplitViewController on iPhone 6 Plus, and I wish to be notified when in portrait mode the user goes back to the master view controller (i.e. when the split view acts like a navigation controller).

Moreover I wish to be notified in my UISplitViewDelegate the same way I am already notified when the user pushes the detail view controller (via the splitViewController:showDetailViewController:sender: callback)

Do you know the easiest (and cleanest) way to do it?

Thanks in advance.

3

There are 3 best solutions below

3
Roman Safin On

In depends on what version of iOS we are trying to do that.

iOS 8.0~8.2 way your project should not be compatible with iOS 7 and will work ONLY iOS 8 and UP the best way is to use Size Classes (Trait collections) presented on WWDC 2014 and there was a video about this way, Session 214 "View Controller Advancements in iOS 8"

Briefly it now has a property This property indicates if detail view is collapsed.(Session 214, Minutes 12:30 ->)

@property (getter=isCollapsed) BOOL collapsed; A bit of KVO magic and you could have a callback of when detail view is available.

For old iOS 7 way you can detect current orientation of device and get current state of your detail.

Couple methods(rotation callbacks) you have:

willRotateToInterfaceOrientation:duration:

didRotateFromInterfaceOrientation:

interfaceOrientation

!!! BASED on Session 214(43:20) it is not recommended to use these methods with iOS 8 and UP because they are deprecated!!!

I'm not sure this 2 way are the best and easiest but they work properly as expected.And little advice to look WWDC videos, they are pretty helpful.

0
Loegic On

To be notified on MasterViewController's return, you'll have to create a delegate and set it to the DetailViewController, in performSegueWithIdentifier for example.

If so, when you will go back to master, the delegate will be fired.

0
malhal On

Because show detail is adaptive, i.e. it either pushes on the master nav in compact width or sets as the split's secondary in regular width and you only want to know when the detail is popped, you'll instead need to use the master navigation controller's delegate which you can also set your app delegate to be.