Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Connecting drill-down NSSplitView outlets using Storyboards

I have an NSSplitView that manages a drill-down hierarchy. The parent/left side displays groups, while the child/right side receives notification that the group selection has changed, and updates to display the child items.

However: When creating an NSSplitView using storyboards, there are 3 scenes created: One for the split view itself, and one for each of the right/left NSViewController instances.

The problem here is that I have two controllers that are also acting as NSTableViewDataSource items, and the parent controller should have an IBOutlet to the child controller so that it can provide direct notification that the selection has changed.

But! Because these controllers are in different scenes, I cannot connect them. Nor can I move them both up to the parent scene for the split view, because they would then not have access to the NSTableView outlets. (Nor would the tables reference the controllers as delegates/datasources.)

Do I need to use NSNotification here? It seems so indirect and wishy-washy, and I haven't found a segue-based approach on the Mac.

enter image description here

like image 427
Craig Otis Avatar asked Aug 10 '14 21:08

Craig Otis


1 Answers

The new NSSplitViewController and NSTabViewController class are what Apple is calling container controllers. you can get references to other controllers within the container using the new property's in NSViewController

@property (readonly) NSViewController *parentViewController
@property (copy) NSArray *childViewControllers

so for example if you would like to get a reference to your child Table controller from your parent table controller. In your parent table controller viewDidLoad you can do the following

myChildTableController = [self.parentViewController childViewControllers][1];

or vice versa from your child table controller

myParentTableController = [self.parentViewController childViewControllers][0];
like image 153
Cory Avatar answered Oct 22 '22 01:10

Cory