Search code examples
objective-cmacoscore-datacocoa-bindings

Cocoa - Bindings - Tableview - How to calculate sum of columns


Let's say I have an Entity named Values and it has three attributes: A, B and SUM.

I have a tableview where Column A and Column B is bound to the attributes A and B. The user can change the values of the first to columns (A,B) but not the third (SUM).

Now to my question: The user should not be able to edit the third column (SUM). That column should only show the sum of A * B. How can I accomplish that? Can I use bindings in IB for that as well?

Many thanks.

SUM = A*B


Solution

  • I fixed it by adding a variable to my entity subclass:

    - (NSUInteger) sumOf1And2 {
        NSUInteger value1 = [self.a intValue];
        NSUInteger value2 = [self.b intValue];
    
        return value1 + value2;
    }