1

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.

Zaphod
  • 6,758
  • 3
  • 40
  • 60
  • Have you had a look at `splitViewController:willChangeToDisplayMode:` [(Apple Docu)](https://developer.apple.com/library/prerelease/ios/documentation/UIKit/Reference/UISplitViewControllerDelegate_protocol/index.html#//apple_ref/occ/intfm/UISplitViewControllerDelegate/splitViewController:willChangeToDisplayMode:) ? As far as I can tell, this method will be called everytime anything in the presentation changes... – luk2302 Mar 07 '15 at 20:57
  • Thanks for your comment, but in fact this method is only called when you change the display mode (automatic, primary hidden, all visible, etc.) and not when the user navigates. Unfortunately what I'm looking for is to be notified when the user in iPhone mode pops back to the master view controller... – Zaphod Mar 08 '15 at 13:00

3 Answers3

0

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.

Roman Safin
  • 704
  • 7
  • 16
  • Thank you for answer, unfortunately I'm not looking to know wether the SplitView is collapsed or not. My problem is when the split view is in phone mode (i.e. both views are not alongside, the master is embed within a navigation controller) : when the user chooses an item in the master it pushes the detail view controller in the navigation stack (managed by the splitview controller). This event can be traced with the `splitViewController:showDetailViewController:sender:` callback. But it is when the user hits the back button, i.e. when the master is shown again, that i want to be notified. – Zaphod Mar 11 '15 at 15:05
  • Hmm, can i ask you? What you want to do? I mean ok, let's pretend you will catch the callback when the master push detail in navigation stack. What next step? – Roman Safin Mar 11 '15 at 15:13
  • On the iPhone 6 +, (the only with a real splitview in landscape and a navigation in portrait) I need to remember which view to collapse when the user switches orientations. For that, I use the callback `splitViewController:collapseSecondaryViewController:ontoPrimaryViewController:` in which I return whether the last view controller displayed was a detail or a master. So I already know when a detail is pushed, but I can't figure out when it is popped back to the master. And as it is in a generic class, I can't really use some dirty trick on the `viewWillAppear:` of the master... You see? – Zaphod Mar 11 '15 at 16:52
0

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.

Loegic
  • 3,390
  • 20
  • 33
0

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.

malhal
  • 26,330
  • 7
  • 115
  • 133