Re: Can't create windows with framework window nib
Re: Can't create windows with framework window nib
- Subject: Re: Can't create windows with framework window nib
- From: Tron Thomas <email@hidden>
- Date: Sat, 21 Feb 2009 14:12:09 -0800
I found that if I derive a class from NSWindowController and use that
in the frame work object then things work. It seems kind of silly to
derive a class just for the purpose the inherited class doesn't
implement anything above what NSWindowController offers, and is just
simple a wrapper to define the class as a new type.
Why does something like this work?
What is the best way to solve this problem?
On Feb 19, 2009, at 8:01 o'clock, Tron Thomas wrote:
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 (email@hidden)
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:
This email sent to email@hidden