【问题标题】:Get selected cell in NSRadioButton in Object C获取对象 C 中 NSRadioButton 中的选定单元格
【发布时间】:2013-07-21 23:52:12
【问题描述】:

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

你能帮帮我吗?提前致谢

【问题讨论】:

    标签: ios objective-c macos cocoa-touch nsmatrix


    【解决方案1】:

    myMatrix 没有标签。

    myMatrix 必须有标签。

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-12-05
        • 1970-01-01
        • 2017-03-04
        • 1970-01-01
        相关资源
        最近更新 更多