0

In Xcode 11.3.1, targeting macOS 10.12, a "master" NSViewController contains a @property (weak, nullable) IBOutlet NSView * contentView;. A non-root NSView from the corresponding XIB file is linked to this contentView property.

The goal is to dynamically load/show/switch different views depending on the application state. These views have corresponding pairs of NSViewController and XIB files.

I am trying to change the current view using this code:

InnerViewController * vc = [[InnerViewController alloc] initWithDefaultNib];
self.contentView = vc.view;

However, I do not see anything. I've double checked that vc.view is not nil.

Have I missed something? Is this the correct approach?

alik
  • 2,244
  • 3
  • 31
  • 44
  • 2
    Did you check the frame of the second view? Alternatively, you can swap views using a container view controller: https://stackoverflow.com/questions/40790267/ – koen Sep 21 '20 at 16:19
  • 1
    You could do that, but you would still have to explicitly remove the original contentView from the view hierarchy, add yours in, and add constraints or autoresizing frame settings. If the "master" NSViewController has code to do that based on whatever you set its contentView to, then it could work. If you are meant to add views as subviews to its contentView, then you would need to take that approach instead. It depends on how the "master" class intends that property to be used. – Carl Lindberg Sep 22 '20 at 01:02

0 Answers0