Custom NSViewController with child NSViewControllers in storyboard?

Hello,


In a macOS storyboard I can put a NSSplitViewController that will display links to two child NSViewController.

Similarly I want to design a custom NSViewController with child view controllers that I can use in storyboard, is it doable ?


When I look at the Connections Inspector of the split view controller in the storyboard, it shows links to "Triggered Segues" bound to "split items". I wonder how to achieve the same with a custom view controller.


I checked the header of NSSplitViewController and it just contains a

@property (copy) NSArray<__kindof NSSplitViewItem *> *splitViewItems;

So there doesn't look to be any specific attribute so that it appears in "Triggered Segues".


If I try to manually create segues from my NSViewController to some other NSViewController, I only get the usual segues like "Show", "Custom", "Modal", "Popover", "Sheet". But I'm not actually interested in a segue in the sense of "transition" between scenes. In documentation NSStoryboardSegue is actually described as "A transition or containment relationship between two scenes in a storyboard.". I'm interested in this containment part, but I don't how to achieve it.

Replies

What do you want to be specific in your subclass ?


Couldn't you use custom class for the 2 child NSViewControllers ? Wouldn't that be enough ?


As far as I understand it, the transition segue is a "normal" segue ; but in the SplitView class, its activation goes with additional code for handling splitView behavior. But I did not dig any further.

I would like to customize the parent view controller that holds the relationship to the child view controller, not just customize the child view controllers.


My current real case is as follow: I want to create a custom NSScrollView that centers its documentView. I was able to do that by using a NSClipView subclass and with a bit of logic in the root view controller. But I want to move that logic to a dedicated controller, and have the documentView managed by a child view controller. That way whenever I need this custom scroll view, I'd just have to drag & drop my custom controller in storyboard and create the connection to an external documentView through a containment segue.


In the meantime I've seen that IB editor provides a "Container View" which kind of does what I want if there's only a single child view controller. The issue with is that it's not reusable : I've created this scroll view managed by my custom controller, and added a container view in it. All in its own storyboard. But then in the main storyboard where I want to reuse this custom view controller, I can't just drag & drop my custom view controller and create a connection (through a containment segue) to a document view.

Could you subclass NSSplitViewController ?

Why should I do that? I’m not interested in split view’s features for my custom view controllers. It was just an example about containment segues that I would like to achieve.

Sorry, I misunderstood what you wanted to do.

No problem, thanks for your time anyway! 🙂