Re: loading NSWindowController nib from bundle
Re: loading NSWindowController nib from bundle
- Subject: Re: loading NSWindowController nib from bundle
- From: Quincey Morris <email@hidden>
- Date: Mon, 27 Oct 2014 23:38:52 +0000
On Oct 27, 2014, at 15:10 , Torsten Curdt <email@hidden> wrote:
>
> My first thought was that passing in "nil" as the owner would actually
> default to "self" I really want - but that does not seem to be the case.
It’s documented as “cannot be nil”.
> On the next thought
>
> controller = [self alloc];
> controller = [controller initWithWindowNibPath:nibPath
> owner:controller];
>
> seems to work - but feels like I am missing something.
This is not a good idea. You have no guarantee that the object returned by ‘[self alloc]’ is the same (or even the same class as) the object returned by ‘[controller init…]’.
I would try something like this:
MyWC* myWC = [[My WC alloc] initWithWindow: nil];
NSWindowController* wc = [[NSWindowController alloc] initWithWindowNibPath: nibPath owner: myWC];
myWC.window = wc.window;
wc.window = nil;
and then investigate whether that memory-manages the NIB objects properly. (That is, the transfer of ownership of the window doesn’t release the nib contents accidentally.)
If that doesn’t lead to a solution, you may, in this special situation, be forced to use a separate class (NOT a NSWindowController subclass) as the NIB owner, and the actual window controller as the window owner (meaning its “window” property points to the window) and window delegate. For this to work, the auxiliary object will need to contain the outlets that would have been in the window controller, and it will have to implement the top level object lifetime management that NSWindowController does for you (which is documented in the NIB loading documentation, IIRC).
_______________________________________________
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