开发者

How to Bind Content Set of NSArrayController to More than One NSArrayController Selection?

开发者 https://www.devze.com 2023-03-15 14:58 出处:网络
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 a开发者_StackOverflows possible without writing code. Is it possible to effectively b

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 a开发者_StackOverflows 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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号