I setup a NSRuleEditor
for user to edit rules to filter an array, I have no trouble for user to edit rules, but I couldn't find a way to display the rules that I saved for user, does anyone have any ideas?
I have rules prepared for each row and returned from the delegate methods, when the user clicked the "+" button, the new rule appeared as I expected
#pragma mark - NSRuleEditorDelegate
- (NSInteger)ruleEditor:(NSRuleEditor *)editor numberOfChildrenForCriterion:(nullable id)criterion withRowType:(NSRuleEditorRowType)rowType {
RuleCriterion *ruleCriterion = criterion;
if (rowType == NSRuleEditorRowTypeCompound) {
if (ruleCriterion == nil) {
return self.compoundCriteria.count;
} else {
return ruleCriterion.numberOfChildren;
}
} else {
if (ruleCriterion == nil) {
return self.simpleCriteria.count;
} else {
return ruleCriterion.numberOfChildren;
}
}
}
- (id)ruleEditor:(NSRuleEditor *)editor child:(NSInteger)index forCriterion:(nullable id)criterion withRowType:(NSRuleEditorRowType)rowType {
RuleCriterion *ruleCriterion = criterion;
if (rowType == NSRuleEditorRowTypeCompound && ruleCriterion == nil) {
return self.compoundCriteria[index];
} else if (rowType == NSRuleEditorRowTypeSimple && ruleCriterion == nil) {
return self.simpleCriteria[index];
} else {
return [ruleCriterion childAtIndex:index];
}
}
- (id)ruleEditor:(NSRuleEditor *)editor displayValueForCriterion:(id)criterion inRow:(NSInteger)row {
RuleCriterion *ruleCriterion = criterion;
return ruleCriterion.displayValue;
}
Insert a row with
Set the criteria and display values of the row with