0

I create radiobutton has 2 row and 1 column and set action for it but it work not correct, it always seleced cell tag =0. This is my codes:

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

Can you help me? Thanks in advance

HTKT611
  • 161
  • 1
  • 1
  • 11

2 Answers2

1

myMatrix does not have a tag.

myMatrix has to have a tag.

Cԃաԃ
  • 1,259
  • 1
  • 15
  • 29
David Bang
  • 115
  • 10
0

You need to set a tag to each button.

enter image description here

El Tomato
  • 6,479
  • 6
  • 46
  • 75