NSRuleEditor:新行的标准

时间:2009-12-19 14:04:23

标签: cocoa

当我点击NSRuleEditor中某行的“+”按钮时,会创建一个新行。如何影响该行使用的标准。

似乎NSRuleEditor默认从可能值列表中顺序选择第一个标准。我宁愿让新行匹配单击“+”的行。

1 个答案:

答案 0 :(得分:2)

我能够通过继承私有方法伪造它:

- (void)_addOptionFromSlice:(id)slice ofRowType:(unsigned int)type
{
    int rowIndex = [(NSRuleEditorViewSlice*)slice rowIndex];

    NSArray *criteriaForRow = [self criteriaForRow:rowIndex];
    NSArray *displayValuesForRow = [self displayValuesForRow:rowIndex];

    self.template = [NSArray arrayWithObjects:criteriaForRow, displayValuesForRow, nil];

    [super _addOptionFromSlice:slice ofRowType:type];
}

- (void)insertRowAtIndex:(NSInteger)rowIndex withType:(NSRuleEditorRowType)rowType asSubrowOfRow:(NSInteger)parentRow animate:(BOOL)shouldAnimate
{
    [super insertRowAtIndex:rowIndex withType:rowType asSubrowOfRow:parentRow animate:shouldAnimate];

    NSArray *template = self.template;

    if (template != nil) {
        [self setCriteria:[template objectAtIndex:0] andDisplayValues:[template objectAtIndex:1] forRowAtIndex:rowIndex];
    }
}