2
votes

I am new to Objective-C, and I love it so far. However, I seem to be running in circles. I am trying to do as much as possible without writing code. Is it possible to effectively bind the Content Set of one NSArrayController to the selections of two other NSArrayControllers.

For example, I want all of the Transactions (NSArrayController) for the selected User (NSArrayController) with selected Seller (NSArrayController). Then when I add new transaction it links to the selected user and seller.

What is the best way to do that so that when I click a new User in an NSTableView bound to the User Controller, the Transactions in an NSTableView bound to a Transactions controller change accordingly but still retain Transactions related to the Seller selected in an NSTableView bound to a Seller controller (and vice versa)?

I may just need to change my perspective since I am used to living in a non-binding world.

Appreciate any help.

1

1 Answers

1
votes

You might regularly configure in IB a "TransactionsForUserAndSeller" NSArrayController with its contentSet bound to userArrayController.selection.transactions then filter the results using its filterPredicate bound to sellerArrayController.selection with a value transformer that returns an NSPredicate.

That value transformer’ implementation might look like this:

+(Class)transformedValueClass { return [NSPredicate class]; }

+(BOOL)allowsReverseTransformation { return NO; }

-(id)transformedValue:(id)value {

    if (value == nil) return nil;

    return [NSPredicate predicateWithFormat:
            [NSString stringWithFormat:@"seller == %@", value]];
}

This would show the subset correctly but you need to write your own add method to handle the relationships manually, getting the current selection through an outlet to the seller array controller.