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 protected])

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to