문제

I have got an event on my NSSlider with this code:

- (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");
}

But it's not firing and the console gives this message: 2011-01-09 19:31:18.994 Nistract[1337:a0f] -[NSSlider value]: unrecognized selector sent to instance 0x100427400

도움이 되었습니까?

해결책 3

Now I use this code and it seems to work:

- (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");
}

다른 팁

The method is executing. You're just crashing because you're trying to execute a method that doesn't exist.

The problem is this line:

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

NSSlider does not have a value method. It has a doubleValue method that returns a double.

You've hard-coded your slider. Instead of calls like this

[optOndoorzichtigheidSlider intValue];

try using the sender

[sender intValue];

And it looks like you are updating a label with the value here

[optOndoorzichtigheidLabel setStringValue:opacity];

When you could consider using Bindings instead.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top