1

我的 NSSlider 上有一个事件,代码如下:

- (IBAction)optOndoorzichtigheidChange:(id)sender {
    NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
    NSString *opacity = [NSString stringWithFormat:@"%d",[optOndoorzichtigheidSlider value]];
    [defaults setObject:opacity forKey:@"opacity"];
    [mainWindow setAlphaValue:[optOndoorzichtigheidSlider doubleValue]];
    [defaults synchronize];
    [optOndoorzichtigheidLabel setStringValue:opacity];
    NSLog(@"fired");
}

但它没有触发,控制台给出了这条消息:2011-01-09 19:31:18.994 Nistract[1337:a0f] -[NSSlider value]: unrecognized selector sent to instance 0x100427400

4

3 回答 3

4

该方法正在执行。你只是因为你试图执行一个不存在的方法而崩溃。

问题是这一行:

NSString *opacity = [NSString stringWithFormat:@"%d",[optOndoorzichtigheidSlider value]];

NSSlider没有value方法。它有一个doubleValue返回double.

于 2011-01-09T19:06:34.260 回答
1

您已经对滑块进行了硬编码。而不是这样的电话

[optOndoorzichtigheidSlider intValue];

尝试使用sender

[sender intValue];

看起来您正在使用此处的值更新标签

[optOndoorzichtigheidLabel setStringValue:opacity];

当您可以考虑使用 Bindings 时。

于 2011-01-10T15:45:40.853 回答
0

现在我使用这段代码,它似乎工作:

- (IBAction)optOndoorzichtigheidChange:(id)sender {
    NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
    NSString *opacity = [NSString stringWithFormat:@"%d",[optOndoorzichtigheidSlider intValue]];
    [defaults setObject:opacity forKey:@"opacity"];
    [[mainWindow animator] setAlphaValue:((double) [optOndoorzichtigheidSlider intValue] / 100)];
    [defaults synchronize];
    [optOndoorzichtigheidLabel setStringValue:opacity];
    NSLog(@"fired");
}
于 2011-01-10T15:34:40.017 回答