Here's an except of some code in a window controller:

> - (id) init {
>       self = [super initWithWindowNibName: @"MyWindow"];
>       …
>       return self;
> }
> 
> + (MyWinController*) myWinController {
>       return [[MyWinController alloc] init];
> }

The key point here is that the MyWinController class, and the MyWindow nib 
file, are both in a private framework, hence not in the main bundle.

On some Macs (10.7 and 10.8) this throws an exception some of the time:

> 9/25/12 6:39:49.700 PM MyApp[1040]: -[MyWinController loadWindow]: failed to 
> load window nib file 'MyWindow'.

According to the documentation, the window controller initWithWindowNibName 
should try to find the nib file in [NSBundle bundleForClass: [self class]], but 
this was apparently returning nil. When I logged this expression, the problem 
vanished. It seems that referencing (creating?) the NSBundle object was enough 
to make the window control init work. That is, this alternative:

> + (MyWinController*) myWinController {
>       [NSBundle bundleForClass: [self class]];
>       return [[MyWinController alloc] init];
> }

seems to fix the problem. Anyone have an idea what's going on here, and what I 
should really do to avoid/fix the problem?




_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to