使用NSRuleEditor无法显示保存的条件

时间:2019-04-15 11:59:46

标签: macos cocoa nsruleeditor

我为用户设置了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;
}

1 个答案:

答案 0 :(得分:0)

使用

插入一行
- (void)insertRowAtIndex:(NSInteger)rowIndex withType:(NSRuleEditorRowType)rowType asSubrowOfRow:(NSInteger)parentRow animate:(BOOL)shouldAnimate;

设置条件并显示行的值

- (void)setCriteria:(NSArray *)criteria andDisplayValues:(NSArray *)values forRowAtIndex:(NSInteger)rowIndex;