• 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
NSObjectController and setManagedObjectContext:
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSObjectController and setManagedObjectContext:


  • Subject: NSObjectController and setManagedObjectContext:
  • From: Kevin <email@hidden>
  • Date: Sun, 11 Feb 2007 17:19:33 -0600

I have an NSTextView whose "value" binding is bound to an NSObjectController. The NSObjectController is created programmatically and uses an NSManagedObject as its content.

My primary reason for binding the text view to the object controller was to have pending edits committed when I saved my managed object context (like when the user chooses Quit or Save without leaving the text view). However, I'm running into a problem when I call setManagedObjectContext: on the object controller. If setManagedObjectContext: is called, my text view doesn't show any text (even though the underlying attribute of the NSManagedObject it's bound to is a non-zero string). If I don't call setManagedObjectContext:, my text view shows the text but pending edits are not committed when I Quit or Save without leaving the text view.

The NSManagedObject is an Entity called "Item" which contains several string attributes, one of which is called "text". The text view is bound to the "text" attribute.

Here's the code I have:

// Get Item
NSManagedObject *item = ...

// Create controller and set it's content to Item
NSObjectController *controller = [[NSObjectController alloc] initWithContent:item];
[controller setManagedObjectContext:[[NSApp delegate] managedObjectContext]];


// Create text view and bind to controller
NSTextView *textView = [[NSTextView alloc] initWithFrame:NSMakeRect (10, 20, 300, 20)];
[textView setRichText:NO];
[textView bind:@"value" toObject:controller withKeyPath:@"selection.text" options:nil];


My understanding is that calling setManagedObjectContext: on the controller is what ties the controller to the context, enabling the context to be notified of pending edits. I'm using bindings in a number of other places in my application and have several controllers (all NSArrayControllers) which are working just fine.

I tried using bind:toObject:withKeyPath:options: for both the "contentObject" and "managedObjectContent" bindings, instead of what I have above, but that didn't seem to make a difference.

Any insight into what I might be doing wrong would be greatly appreciated.

- Kevin


_______________________________________________

Cocoa-dev mailing list (email@hidden)

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


  • Prev by Date: Resizing an NSButtonCell
  • Next by Date: NSCell drawing
  • Previous by thread: Re: Resizing an NSButtonCell (SOLVED)
  • Next by thread: NSCell drawing
  • Index(es):
    • Date
    • Thread