• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: loading NSWindowController nib from bundle
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: loading NSWindowController nib from bundle
      • From: Torsten Curdt <email@hidden>
References: 
 >loading NSWindowController nib from bundle (From: Torsten Curdt <email@hidden>)

  • Prev by Date: Mac containment segues, and prepareForSegue
  • Next by Date: Editing an NSOutlineView item
  • Previous by thread: loading NSWindowController nib from bundle
  • Next by thread: Re: loading NSWindowController nib from bundle
  • Index(es):
    • Date
    • Thread