我设置了一个NSRuleEditor
供用户编辑规则以过滤数组,我没有麻烦用户编辑规则,但我找不到显示我为用户保存的规则的方法,有人有什么想法吗?
我为每一行准备了规则并从委托方法返回,当用户单击“+”按钮时,新规则按我的预期出现
#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;
}