Reputation: 23
This question may have been asked similarly relating to iOS, but not OS X. I've been struggling for three days to simply try and embed an NSView
or NSViewController
within an NSView
using storyboards.
This works fine using a .xib or .nib: (when the next button is pushed it displays either customView1 or customView2 within the Container View.
Trying to use a storyboard it does not work. In fact I have no concept or clue on how to connect, embed, call, summons, or beg customView1
or customView2
to get itself inside Container View.
It seems I cannot access anything outside of it's own View Controller!?!
Example of properly working functionality (from .nib):
Upvotes: 2
Views: 4079
Reputation: 25619
Here's one way to do it.
You can add two "Container View" objects to your main view controller, as top level objects, and connect them to NSView
outlets in your controller. This will automatically create two new view controller scenes, with Embed
segues from the container view to the child view controller.
Your view controller now has references to two inner NSViews and you can manipulate them as you wish.
If you need a reference to the child view controllers, assign a storyboard identifier to each Embed
segue and implement -prepareForSegue:sender:
- (void)prepareForSegue:(NSStoryboardSegue*)segue sender:(id)sender
{
if ([segue.identifier isEqual:@"Embed1"])
{
_innerController1 = segue.destinationController;
}
else if ([segue.identifier isEqual:@"Embed2"])
{
_innerController2 = segue.destinationController;
}
}
Alternatively to segues, you can assign a storyboard identifier to each of your inner view controllers, and instantiate them in code from the storyboard:
_innerController1 = [self.storyboard instantiateControllerWithIdentifier:@"InnerController1"];
You're also free to mix Storyboards and NIBs, so you can design your inner views in a separate NIB and instantiate them in code.
Upvotes: 2