NSButtonCell *prototype = [[NSButtonCell alloc] init];
[prototype setTitle:@"Watermelons"];
[prototype setButtonType:NSRadioButton];
NSRect matrixRect = NSMakeRect(20.0, 20.0, 125.0, 125.0);
NSMatrix *myMatrix = [[NSMatrix alloc] initWithFrame:matrixRect
mode:NSRadioModeMatrix
prototype:(NSCell *)prototype
numberOfRows:3
numberOfColumns:1];
[[[typeField window] contentView] addSubview:myMatrix];
NSArray *cellArray = [myMatrix cells];
[[cellArray objectAtIndex:0] setTitle:@"Apples"];
[[cellArray objectAtIndex:1] setTitle:@"Oranges"];
[[cellArray objectAtIndex:2] setTitle:@"Pears"];
[prototype release];
[myMatrix release];
фрагмент кода из Использование радиокнопок в документации Apple.
Обратите внимание на использование прототипа NSButtonCell
- таким образом, мы можем NSMatrix
сообщить, что кнопки NSRadioButton
тип должен использоваться (что не может быть сделано, используя только класс ячейки, кажется)