Best Way To Bind Sum/Difference of Two Arrays?
Best Way To Bind Sum/Difference of Two Arrays?
- Subject: Best Way To Bind Sum/Difference of Two Arrays?
- From: Chris Tracewell <email@hidden>
- Date: Sat, 31 Jul 2010 12:03:52 -0700
I have two arrays, A and B, that each contain objects that have a myTotal property. In IB I use an array controller for each and show their contents in separate NSTableview's and then display the sum for each by binding to respective NSTextField's using the @sum array operator on their arrangedObjects property.
Now I want to bind the difference between array A and array B but am having problems. In my model where the arrays reside, I added a readonly property for myDifference. I implemented the method for -(NSDecimalNumber *)myDifference like so...
-(NSDecimalNumber *) myDifference
{
NSDecimalNumber *theTotalArrayA = [self valueForKeyPath:@"email@hiddenal"];
NSDecimalNumber *theTotalArrayB = [self valueForKeyPath:@"email@hiddenal"];
return [theTotalArrayA decimalNumberBySubtracting: theTotalArrayB];
}
This works when the view is first loaded but does not change myDifference when the user changes A or B total in the UI. To get myDifference to adjust I implementing in the model...
+(NSArray*)keyPathsForValuesAffectingMyDifference
{
return [NSArray arrayWithObjects: @"myArrayA",@"myArrayB",nil];
}
This works if I add or remove items to the arrays but does not change myDifference if myTotal is changed for any of the objects in either of the arrays. How do I achieve this? Should I manually observe change in the controller using controlTextDidEndEditing delegate for the TableView's and then send a setMyDifference message to the model object? Or am I missing a more elegant solution?
Thanks
-- Chris_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden