xamarin.iosuisplitviewcontrolleruisplitviewdelegate

Hiding master UISplitViewController for only certain views


I have a UISplitViewController which has a UINavigationController in the master and a UIViewController in the detail. When the device is orientated into landscape mode I want the normal behaviour to be preserved. I.e. The master gets shown in landscape and hidden in portrait.

However depending what the user clicks in the master depends on which UIViewController is loaded into the detail part of the UISplitViewController. What I would like is for the master to be hidden in landscape mode when a user clicks on a button in the detail UIViewController. The problem is I can't get this to work.

My delegate looks like this (have removed some lines for simpler viewing):

public class SplitControllerDelegate : UISplitViewControllerDelegate {
                    SplitViewController incomingController;

     private bool hideMaster = false;

     public override bool ShouldHideViewController (UISplitViewController svc,        
                                       UIViewController viewController, 
                                       UIInterfaceOrientation inOrientation) {
          return hideMaster;
     }
     public void SetHideMaster(bool value) {
          hideMaster = value;
     }

}

I then call it from the detail UIViewController like

   splitControllerDelegate.SetHideMaster(value);

However nothing changes. I'm unsure of how to make it perform the change? Should the master disappear immediately? What causes the WillHideViewController to fire?

Thanks

Mike


Solution

  • What you're trying to do cannot be done officially. ShouldHideViewController() is called only upon device rotation. So unless you rotate forth and back, your controller won't disappear.

    You have various options:

    About the last point. You should be able to force ShouldHideViewController() being called if you set the Delegate property to NULL and then assign a new delegate. Afterwards, call the WillRotate() method of the split view controller using the current orientation.

    I'd go for the 2nd option.