• 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: Easy Question re NSWindowController
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Easy Question re NSWindowController


  • Subject: Re: Easy Question re NSWindowController
  • From: Graham Cox <email@hidden>
  • Date: Mon, 7 Sep 2009 10:39:10 +1000


On 05/09/2009, at 10:42 PM, Brad Gibbs wrote:

If I create the NSWindowController programmatically with a custom initializer:

NSWindowController *myWindowController = [[NSWindowController alloc] initWithWindowNibName:@"MyWindow" moc:self.managedObjectContext];

everything works fine. I can also pass the managedObejctContext separately without breaking anything.

Hi Brad,

So, you've discovered that custom designated initializers don't work. That's to be expected, since IB/nibs are not aware of how your code is structured a priori, and there's no way to indicate which method is the designated initializer.

I usually deal with this kind of issue using informal protocols that are known to the window controller plus any delegate that wants to use them. For example:

@interface NSObject (MyWindowControllerDelegateInformalProtocol)

- (id) willReturnManagedObjectContextForWindowController: (MyWindowController*) controller;

@end

Then your controller needs a setDelegate method, or a delegate outlet, and it will call the delegate with this method when it needs the information. This works with nibs and is a good general purpose solution. It also keeps the window controller self-contained and very likely reusable as well.

--Graham


_______________________________________________

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


References: 
 >Easy Question re NSWindowController (From: Brad Gibbs <email@hidden>)

  • Prev by Date: Re: NSString drawAtPoint and vertical font alignment
  • Next by Date: Re: Does Mac OS X support interior pointers?
  • Previous by thread: Re: Easy Question re NSWindowController
  • Next by thread: NSString width
  • Index(es):
    • Date
    • Thread