[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Design issue for MVC and database updates
Thank you for your reply.
Key-value observing does seem like the right way to do this. I'll give
it a try.
Joakim
On 2004-03-03, at 00.55, Scott Stevenson wrote:
>
> On Mar 2, 2004, at 3:03 PM, Joakim Danielson wrote:
>
>> Well the problem is not in the database methods really but more what
>> I must implement to see which object's how has changed. But I supply
>> the method anyway:
>>
>> - (IBAction)saveToDb:(id)sender
>
> Your best bet is probably key-value observing (Panther only):
> http://developer.apple.com/documentation/Cocoa/Conceptual/
> KeyValueObserving/
>
> You can observe each item, and whenever the a value changes in the
> object, you can add them item to a "changedObjects" mutable array.
> This is probably best done outside of the NSArrayController.
>
>
> Then, you change your database saving action method to this:
>
> - (IBAction)saveToDb:(id)sender {
>
> NSEnumerator *iterator;
> JDTransactionType *item;
> int newId;
>
> // get the list of changed objects
> NSMutableArray * changedObjects = [self changedObjects];
> iterator = [changedObjects objectEnumerator];
>
> ....
>
> // after you're done, empty the array
> [objectsToUpdate removeAllObjects];
> }
>
>
> I haven't yet found a way to ask NSArrayController which object it
> just edited (although it seems like a something a lot of people would
> use). But if someone else has, that would negate the need to observe
> each object separately.
>
> I guess it would be pretty easy to override -objectDidBeginEditing to
> check -selection and add it to an array, or something of that nature.
> Not sure if it's reasonable to assume the selection is the one being
> edited.
>
> - Scott
>
> --
> Tree House Ideas
> http://treehouseideas.com/
>
> _______________________________________________
> MacOSX-dev mailing list
> MacOSX-dev@xxxxxxxxxxxxx
> http://www.omnigroup.com/mailman/listinfo/macosx-dev
>