Search code examples
cocoamacosnsslider

NSSlider event not firing


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


Solution

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