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 protected]"];
NSDecimalNumber *theTotalArrayB = [self
valueForKeyPath:@"[email protected]"];
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 protected])
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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to [email protected]