如何在XCode5(可可)中通过标记以编程方式选择NSMatrix无线电

时间:2014-06-12 22:22:38

标签: objective-c cocoa tags radio-button nsmatrix

我正在为MacOSX开发应用程序,我正在创建一个像这样的NSMatrix(Radio Buttons):

arrayClasifCuentas = [[NSMutableArray alloc]init];
[arrayClasifCuentas addObject:@{@"tag": @"7",@"value": @"Seven"}];
[arrayClasifCuentas addObject:@{@"tag": @"8",@"value": @"Eight"}];
[arrayClasifCuentas addObject:@{@"tag": @"9",@"value": @"Nine"}];

NSButtonCell *prototype = [[NSButtonCell alloc] init];
[prototype setTitle:@"Radio"];
[prototype setButtonType:NSRadioButton];

NSRect matrixRect = NSMakeRect(20, 20, 125, 80);

myMatrix = [[NSMatrix alloc] initWithFrame:matrixRect
                                      mode:NSRadioModeMatrix
                                 prototype:(NSCell *)prototype
                              numberOfRows:[arrayClasifCuentas count]
                           numberOfColumns:1];

NSArray *cellArray = [myMatrix cells];

for (int i = 0; i < [arrayClasifCuentas count]; i++) {

    [[cellArray objectAtIndex:i] setTitle:[[arrayClasifCuentas objectAtIndex:i] objectForKey:@"value"]];
    [[cellArray objectAtIndex:i] setTag:  [[[arrayClasifCuentas objectAtIndex:i] objectForKey:@"tag"]intValue ]];
}

我接下来要做的是以编程方式选择七个选项但是基于它自己的标签(7)如何做到这一点???

1 个答案:

答案 0 :(得分:1)

试试这个

[myMatrix selectCell:[myMatrix cellWithTag:7]];