0

我创建单选按钮有 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;
    }}

你能帮助我吗?提前致谢

4

2 回答 2

1

myMatrix没有标签。

myMatrix必须有标签。

于 2013-07-23T05:35:20.463 回答
0

您需要为每个按钮设置一个标签。

在此处输入图像描述

于 2013-07-23T06:20:27.507 回答