I am trying to write a framework that contains a window nib which can be used to create a window on demand by the application linking into the framework.

The framework originally contained a singleton object was defined similar to this:

@interface FrameworkObject : NSWindowController
{
        // instance members ...
}
+ (FrameworkObject*)sharedFrameworkObject;
// declared messages ...
@end

The FrameworkObject was set as the owner of the window nib contained in the framework. The object responded to the init message like this:

- (id)init
{
        self = [super initWithWindowNibName:@"FrameworkWindowNib"];
        if(nil == self){
                return nil;
        }
        
        // initialize instance members ...
        
        return self;
}

This worked fine. The object would load the window nib and create the window.

I then decided that I did not want this object to be an NSWindowController, and I also wanted the ability to create multiple windows. So, I changed the window nib owner to NSWindowController and then changed the class interface for FrameworkObject to something like:

@interface FrameworkObject : NSObject
{
@private
        NSMutableArray* _controllers;
        
        // other instance members ...
}
+ (FrameworkObject*)sharedFrameworkObject;
// declared messages ...
@end

The init message response was now:

- (id)init
{
        self = [super init];
        if(nil == self){
                return nil;
        }
        
        _controllers = [[NSMutableArray alloc] init];
        
        // initialize other instance members ...
        
        return self;
}

When the object needed to display a window it would try to do the following:

- (void)showWindow
{
        NSWindowController* controller = [[NSWindowController alloc]
                initWithWindowNibName:@"FrameworkWindowNib"];
                
        NSWindow* window = [controller window];
        [window setDelegate:self];
                
        [_controllers addObject:[controller autorelease]];
}

However this fails at runtime with an error like the following:
-[NSWindowController loadWindow]: failed to load window nib file 'FrameworkWindowNib'

It is very puzzling why when FrameworkObject was derived from NSWindowController it could successfully find and load the window nib, and when FrameworkObject is change to create an NSWindowController, that NSWindowController cannot find the window nib.

What is needed so the framework can use its window nib to create multiple windows?

_______________________________________________

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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

Reply via email to