0

I'm trying to add an NSPopOver to my app but only load it when running 10.7 or later. I've put the popover, view controller & view in a separate xib and have loaded it with

BOOL loaded = [NSBundle loadNibNamed:@"Popovers.xib" owner:self];

from inside my app delegates' awakeFromNib method. The xib loads ok (loaded is YES) but the outlet, pointing to the NSPopover, remains null. Is there a problem with loading the xib inside the awakeFromNib method?

Interestingly, when I didn't include the .xib extension in the file name it crashed.

Andy B
  • 1
  • 1

1 Answers1

1

If I got that right, NSBundle's loadNibNamed:owner: method will only load the bundle, but not instantiate the top-level objects. You can do this by using an appropriate NSNib method, e.g. instantiateNibWithOwner:topLevelObjects:.

I prefer to load the nib by creating a NSViewController subclass instance:

viewController = [[MyViewController alloc] initWithNibName:@"name" bundle:[NSBundle mainBundle]]

and then instantiate the Nib inside the custom view controller's -(id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil method:

[self loadView];
Tim
  • 1,659
  • 1
  • 21
  • 33