• 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: Torsten Curdt <email@hidden>
  • Date: Tue, 28 Oct 2014 02:16:01 +0100

>
> 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”.
>

Yup - and it also barfs if it is :)
Still it was my first thought and expectation.


> 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 know - it smells horrible. Hence my post.



> 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.)
>

Hm. Interesting - I don't see yet how that would work with the outlets yet
though.



> 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).
>

Urgh. That's sound pretty horrible, too.


My next thought was to just add

    - (id) initWithMyWindowNibPath:(NSString *)nibPath
    {
        return [super initWithWindowNibPath:nibPath owner:self];
    }

to my controller.

Too pragmatic?

cheers,
Torsten
_______________________________________________

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: Quincey Morris <email@hidden>
References: 
 >loading NSWindowController nib from bundle (From: Torsten Curdt <email@hidden>)
 >Re: loading NSWindowController nib from bundle (From: Quincey Morris <email@hidden>)

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