Forum Xamarin.iOS
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

NSSplitView autosave feature not working

danipendanipen USMember ✭✭
edited September 2016 in Xamarin.iOS

Hi, I'm playing with the NSSplitView autosave feature, and I'm unable to get it working. I have a very simple example, where I create a simple split view, set a delegate and assign an autosave name:

        void Initialize ()
            NSSplitView splitView = CreateSplitter("MySplitView", true);
            splitView.Delegate = new MySplitViewDelegate();

            splitView.AddSubview (new NSView ());
            splitView.AddSubview (new NSView ());

            ContentView = splitView;

        static NSSplitView CreateSplitter(string name, bool bIsVertical)
            NSSplitView result = new NSSplitView();
            result.Identifier = "ID_" + name;
            result.AutosaveName = name;
            result.IsVertical = bIsVertical;
            result.DividerStyle = NSSplitViewDividerStyle.Thin;

            return result;

This is the implementation for the SplitViewDelegate:

    internal class MySplitViewDelegate : NSSplitViewDelegate
        public override bool ShouldAdjustSize(NSSplitView splitView, NSView subview)
            return true;

        public override bool CanCollapse(NSSplitView splitView, NSView subview)
            return true;

        public override bool ShouldCollapseForDoubleClick(NSSplitView splitView, NSView subview,
            int doubleClickAtDividerIndex)
            return true;

When I move the splitter and close the application and load the application again, the divider position is not remembered at all.

I noticed that the following data is written to the UserDefaults file (attached image).

But unfortunately this makes no sense for me. Some Google work did not help here :-(

Am I doing something wrong? Someone could explain how the autosave feature for NSSplitView works?

Thanks in advance!

Best Answer


  • ChrisHamonsChrisHamons USForum Administrator, Xamarin Team Xamurai

    What macOS are you on? suggests that it's broken on some macOS versions. Since radar is less that awesome, I can't check the status of that though. :(

    Another thing is that it could be magic that happens when you are deserializing from a xib (the documentation does not say much). Try making a tiny example with the splitter (and subviews) are already dropped in a xib/storyboard, and see if that autosaves (make sure to set the id/autosave thing there like you are here).

  • danipendanipen USMember ✭✭
    edited October 2016

    Hi Chris, thanks for your reply. I trying macOS 10.6.8. Did you see the strange .pList file that is saved into the NSUserDefaults? (attached)

  • ChrisHamonsChrisHamons USForum Administrator, Xamarin Team Xamurai

    I hacked up a quick example in obj-c:

    and I see the same exact behavior.

    In that obj-c example, I also see the plist info you mention

    $ cat ~/Library/Preferences/Test.SplitViewRestoreTest.plist
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "">

    NSSplitView Subview Frames MySplitView

    0.000000, 0.000000, 59.000000, 270.000000, NO, NO
    68.000000, 0.000000, 412.000000, 270.000000, NO, NO

    I am unsure if this is a bug in your use of the API (I did a straight convert of your example), or a bug in Cocoa. As I mentioned before, you could try to drop an NSSplitView and the children in Interface Builder instead of creating everything in code and see if that changes things.

  • ChrisHamonsChrisHamons USForum Administrator, Xamarin Team Xamurai


    Yep, that fixed my obj-c version as well. Good catch.

Sign In or Register to comment.