When you connect the view
outlet of the NSViewController
to the empty generic container view, it's replacing the actual view loaded from the NIB with the empty view at runtime.
Unfortunately there's no way to do what you're asking purely by using Interface Builder and outlets. The easiest alternative method:
Add the NSViewController
object to the main XIB file and set the Nib Name and Nib Bundle in the Attributes inspector, but don't set the view outlet to the empty container view.
Add properties to your application delegate (or other controller class exposed in the XIB) to create IBOutlet
s to the view controller and container view. Example:
@property (nonatomic, strong) IBOutlet NSViewController *viewController; // view controller in XIB
@property (nonatomic, weak) IBOutlet NSView *containerView;
Connect these outlets in the XIB to the view controller and container view. Now, at runtime, add the view controller's view as a subview of the container view:
NSView *realView = self.viewController.view;
realView.frame = self.containerView.bounds;
// Also configure autoresizing behaviour for realView using either autoresizing masks
// or layout constraints so that realView resizes with its parent container
[self.containerView addSubview:realView];