On Jul 31, 2009, at 20:03, Richard Somers wrote:

I am having problems binding an auxiliary panel with the document's managed object context. The panel is in nib separate from the document nib. My code looks like this.

@interface AuxPanelController : NSWindowController
{
@private
   NSManagedObjectContext *managedObjectContext;
}

@implementation AuxPanelController

- (id)init
{
   if (![super initWithWindowNibName:@"AuxPanel"])
       return nil;
   return self;
}

- (NSManagedObjectContext *)managedObjectContext
{
   return [[self document] managedObjectContext];
}

In the AuxPanel.xib the array controller's managed object context is bound to the File's Owner managedObjectContext model key path. The File's Owner object is the AuxPanelController.

In the running application the auxiliary panel displays properly but an error message is produced: "Cannot perform operation without a managed object context".

You haven't said what you mean by an "auxiliary panel".

If you mean it's a sheet on the document window, then its window controller's "document" property will be nil. You should pass the document as a parameter to the AuxPanelController's initializer instead.

If you mean it's a freestanding window (whether NSWindow or NSPanel), the answer is the same: pass the document because there's no other way.

If you mean it's a secondary document window, then you need to add it to the document's list of window controllers. That would need to be done by whatever creates is -- typically the window controller of the main document window. After that's done, AuxPanelController can refer to [self document] and get the document.

Or, in all 3 cases, just pass the managed object context to the AuxPanelController initializer, and stash it in your otherwise unused instance variable.

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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 arch...@mail-archive.com

Reply via email to