I am trying to generate an NSPredicateEditorRowTemplate
that on the left side has a number of property names from an entity Foo, among which is the property bar. When the user selects 'bar', the right side should become popup which contains all values of 'bar'.
How can I best populate the right side popup? All unique values of bar are stored in an NSMutableArray
, so perhaps I can use KVO to change the row template when the array changes.
Is there a way that I can use code to easily change the values in a right side popup in an NSPredicateEditor
row? I can enter a few static values in IB, but that will not do in this situation.
EDIT
Having read a good deal of related Q&A's, including NSPredicateEditor in Xcode 4 and the excellent answer to it by @Dave DeLong, I think a good bit of the work can be done like this:
NSArray *leftexp = @[[NSExpression expressionForKeyPath:@"name"],[NSExpression expressionForKeyPath:@"married"]];
NSArray *rightexp = @[[NSExpression expressionWithFormat:@"One"],[NSExpression expressionWithFormat:@"Two"]];
NSPredicateEditorRowTemplate *template = [[NSPredicateEditorRowTemplate alloc] initWithLeftExpressions:leftexp rightExpressions:rightexp modifier:NSDirectPredicateModifier operators:@[@(NSEqualToPredicateOperatorType)] options:0];
NSPredicateEditorRowTemplate *compound = [[NSPredicateEditorRowTemplate alloc] initWithCompoundTypes:@[@(NSOrPredicateType)]];
[self.predicateEditor setRowTemplates:@[template,compound]];
NSEntityDescription *description = [NSEntityDescription entityForName:@"Person" inManagedObjectContext:self.managedObjectContext];
self.predicate = [NSPredicate predicateWithFormat:@"name == ''"];
I've seen a few ways to make the basic NSPredicateEditor appear (with at least the compound line), but it seems to me that there has to be an elegant way to do that, the way it was meant to be done. Can't find that though, can anyone help me along with this?