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 に答える