2009-12-19 12 views
5

當我在NSRuleEditor的某行上點擊「+」按鈕時,會創建一個新行。我如何才能對該行使用的標準產生影響。NSRuleEditor:新行的標準

看來NSRuleEditor默認從可能值列表中順序選擇第一條標準。我寧願讓新行匹配點擊「+」的行。

回答

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]; 
    } 
}