简体   繁体   中英

how to select programmatically NSMatrix radio by tag in XCode5 (cocoa)

I'm developing an app for MacOSX and I'm creating a NSMatrix (Radio Buttons) like this:

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

what I wanna do next is to programmatically select the option seven but based on its own tag (7) how to do that???

尝试这个

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM