【问题标题】:How to deselect radio button in cocoa如何取消选择可可中的单选按钮
【发布时间】:2013-08-09 19:58:35
【问题描述】:

我是新手。我对 NSMatrix 有疑问。 我创建了多个 NSMatrix,但我想先加载,他们没有检查。 我使用此代码创建它们,但它总是检查。

 prototype= [[NSButtonCell alloc] init];
    [prototype setTitle:@""];
    [prototype setButtonType:NSRadioButton];
    NSRect matrixRect = NSMakeRect(400, textfield_Y, 50, 20);
    myMatrix = [[NSMatrix alloc] initWithFrame:matrixRect
                                          mode:NSRadioModeMatrix
                                     prototype:(NSCell *)prototype
                                  numberOfRows:1
                               numberOfColumns:1];
    [myMatrix setTag:300+i];
    //[myMatrix setAction:@selector(radioButtonClicked:)];
    [myMatrix setTarget:self];
    NSArray *cellArray = [myMatrix cells];
    [[cellArray objectAtIndex:0] setTag:0];
    [guiView addSubview:myMatrix];
    [prototype release];
    [myMatrix release];

有什么想法吗?非常感谢

【问题讨论】:

    标签: objective-c macos cocoa nsmatrix


    【解决方案1】:

    在 NSButtonCell 上,您将使用 setStateNSCell 方法:

    [prototype setState:NSOffState]

    【讨论】:

    • 其他设置是否有效(例如标题)?它可能是代码第 3 行中的 NSRadioButton 设置。使用单选按钮时,必须始终选中一个。你可以试试NSSwitchButton 吗?
    猜你喜欢
    • 2019-06-16
    • 1970-01-01
    • 2012-02-21
    • 1970-01-01
    • 2011-07-17
    • 1970-01-01
    • 2013-10-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多