Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

gigantor

macrumors newbie
Original poster
Oct 12, 2008
3
0
Melbourne, Australia
Hi,

I have a basic core data app with a view using core data bindings to display fields of a managed object. When the object is saved via APIs the bound data used core data bindings does not refresh.

How do I update/refresh views following a core data object save ?
 

Littleodie914

macrumors 68000
Jun 9, 2004
1,813
8
Rochester, NY
It's been a while, but...

It really depends on the class of the view you're updating. An NSView, for example, would be best updated calling:

Code:
[myView setNeedsDisplay];

While an instance of NSTableView would be updated calling:

Code:
[myTableView reloadData];
:)
 

gigantor

macrumors newbie
Original poster
Oct 12, 2008
3
0
Melbourne, Australia
Thanks for that but I was wondering if there was a way to cause the refresh from the Core Data layer upwards rather than from the GUI View layer.

I guess I am looking for a way for Core Data managed objects to notify interested views etc when data in a managed object changes, ie in my case, saving an updated managed object would cause views with bindings to that managed object to get notified to refresh their displays.

Does anyone know of an existing mechanism on Cocoa or core data to do this ?
 

HiRez

macrumors 603
Jan 6, 2004
6,265
2,630
Western US
Is the saving of a Core Data object separate from updating bindings? Don't the bindings get updated when the managed object changes in the context instead of when it gets saved back to storage from the context (and then undone if changes are not saved)?

Anyway, if you are setting data programmatically, can you wrap the changes in NSObject's -willChangeValueForKey: and -didChangeValueForKey: calls to trigger propogation of the changes to your view objects? I dunno, that might work.
 

gigantor

macrumors newbie
Original poster
Oct 12, 2008
3
0
Melbourne, Australia
Hi,

I got the issue solved. My program had inadvertently created a separate NSManagedObjectContext object seperate from the instance used by the interface builder generated classes.

Once I updated the code to use the context created in the Interface Builder class then everything worked as expected. Updating and saving a managed object programmatically caused the GUI to update automatically as expected.

Regards,
Gigantor
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.