NSRuleEditor:新行的标准

Pie*_*ard 5 cocoa

当我按下NSRuleEditor中某行的"+"按钮时,会创建一个新行.如何影响该行使用的标准.

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

Pie*_*ard 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];
    }
}
Run Code Online (Sandbox Code Playgroud)