我创建单选按钮有 2 行和 1 列并为其设置操作但它工作不正确,它总是选择单元格标记 = 0。这是我的代码:
NSButtonCell *prototype= [[NSButtonCell alloc] init];
[prototype setTitle:@"Normal"];
[prototype setButtonType:NSRadioButton];
NSRect matrixRect = NSMakeRect(170, 130, 150, 125.0);
NSMatrix *myMatrix = [[NSMatrix alloc] initWithFrame:matrixRect
mode:NSRadioModeMatrix
prototype:(NSCell *)prototype
numberOfRows:2
numberOfColumns:1];
[myMatrix setAction:@selector(radioButtonClicked:)];
[myMatrix setTarget:self];
[guiView addSubview:myMatrix];
NSArray *cellArray = [myMatrix cells];
//[[cellArray objectAtIndex:0] setTitle:@"Normal"];
[[cellArray objectAtIndex:1] setTitle:@"Mute"];
[prototype release];
[myMatrix release];
- (IBAction)radioButtonClicked:(NSMatrix * )sender {
//thoahuynh - check selected tag of radio button
NSInteger tag = [[sender selectedCell] tag];
switch ( tag ) {
case 0:
NSLog(@"Selected Normal");
break;
case 1:
NSLog(@"Selected Mute");
break;
}}
你能帮助我吗?提前致谢