Re: NSObjectController and Core Data
Re: NSObjectController and Core Data
- Subject: Re: NSObjectController and Core Data
- From: Kevin <email@hidden>
- Date: Thu, 22 Feb 2007 08:03:28 -0600
I believe I've determined the cause of the problem. I created a
simple Core Data App consisting of a window with a NSTextView, a
NSObjectController, and a single Entity. For the first run, I created
the NSObjectController in the nib file and bound the NSTextView to
it. The NSObjectController was setup to be "Entity" mode. When I ran
the app, I was able to make changes to the NSTextView and then save
my changes WITHOUT leaving the NSTextView. It was working.
For the second test run, I ripped out the NSObjectController from the
nib file and created it programmatically. This time, I saw the same
problem I've seen before. Changes in the NSTextView were not recorded
if I attempted to save the managed object context without leaving the
NSTextView.
If I print the controller using NSLog, I get different results
depending on whether the controller was created in the nib file or
programmatically:
Console log when NSObjectController created in nib:
2007-02-22 07:37:44.006 ObjectController[233] object
controller:<NSObjectController: 0x358940>[entity: MyEntity] <---
Entity Mode
Console log when NSObjectController created programmatically:
2007-02-22 07:36:35.619 ObjectController[186] object
controller:<NSObjectController: 0x32cd30>[object class:
NSMutableDictionary] <--- Object Mode
Even though the object controller is created in identical fashion in
both nib file and programmatically, the one created programmatically
seems to be stuck in "Object" mode. I've called setEntityName:, which
according to the docs , should switch it to "Entity" mode to an
avail. I also subclassed NSObjectController and overrode
commitEditing:, objectDidEndEditing:, objectDidBeginEditing: to put
NSLogs and simply called super's implementation. When attempting to
save the managed object context, commitEditing: never gets called
even though changes in the NSTextView are recorded by calls to
objectDidBeginEditing:. If I explicitly call [[self
managedObjectContext] objectDidBeginEditing:self] in
objectDidBeginEditing: and do the same in objectDidEndEditing:,
everything works.
The object controller appears to be constructed differently in the
nib file, correctly setting it in "Entity" mode. If anyone knows how
I can force the controller to be in "Entity" mode programmatically,
I'd like to hear it.
Kevin
On Feb 14, 2007, at 5:03 PM, Scott Anguish wrote:
I'm guessing that this is because the NSTextView/Controllers aren't
using the NSEditor protocol properly to ensure that the bindings
update automatically before you save.
I'm sure there is a bug about this somewhere. You'll basically
need to force the first responder to resign before saving in order
to bypass this (and file a bug asking for a way to have controllers
expose a way to do this cleanly)
On Feb 14, 2007, at 3:50 PM, Kevin wrote:
When I edit the contents in any of the text views and then decide to
save my managed object context WITHOUT leaving the text view, the
changes are not recorded. If I leave the text view, the changes do
get recorded.
_______________________________________________
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