0

When I create a new "Master Detail App" with Visual Studio for Mac (v8.4.5), the default behavior of the UISplitViewController is to show the Detail page first when it appears on an iPhone in Portrait mode.

I would rather (as I think most people would rather) have the Master page show by default. In my case, the Master page is a table view that holds a list of contacts.

This question is similar to: UISplitViewController in portrait on iPhone shows detail VC instead of master but for Xamarin.iOS

Similar to the solutions suggested there, I have attempted to assign a delegate without success:

    public class ContactsSplitViewControllerDelegate : UISplitViewControllerDelegate
    {
        public override bool EventShowViewController(UISplitViewController splitViewController, UIViewController vc, NSObject sender)
        {
            return true;
        }

        public override bool EventShowDetailViewController(UISplitViewController splitViewController, UIViewController vc, NSObject sender)
        {
            return true;
        }
    }

    public partial class ContactsSplitViewController : UISplitViewController
    {
        public ContactsSplitViewController (IntPtr handle) : base (handle)
        {
            this.Delegate = new ContactsSplitViewControllerDelegate();
        }

    }
JR Lawhorne
  • 3,192
  • 4
  • 31
  • 41

2 Answers2

0

set the PreferredDisplayMode

public override void ViewDidLoad()
{
    base.ViewDidLoad();

    this.PreferredDisplayMode = UISplitViewControllerDisplayMode.AllVisible;
}
Jason
  • 86,222
  • 15
  • 131
  • 146
0

After some experimentation, it seems that overriding CollapseSecondViewController on the delegate will work though I'm not yet convinced it's the proper solution.

using Foundation;
using System;
using UIKit;

namespace MasterDetailTest
{
    public class SplitViewControllerDelegate : UISplitViewControllerDelegate
    {
        public override bool CollapseSecondViewController(UISplitViewController splitViewController, UIViewController secondaryViewController, UIViewController primaryViewController)
        {
            return true;
        }
    }

    public partial class MainPageSplitViewController : UISplitViewController
    {
        public MainPageSplitViewController (IntPtr handle) : base (handle)
        {
            this.Delegate = new SplitViewControllerDelegate();
        }

        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            // When implemented in my project, I found I needed to set this
            // or the delegate would not be called.
            this.SetNeedsFocusUpdate();
        }

    }
}
JR Lawhorne
  • 3,192
  • 4
  • 31
  • 41