anil
anil

Reputation: 1

How do I recieve the current value of a slider in code? in cocoa

i have draged vertical slider in my ui and lable for to show the slider value when i move the slider. i have written following ibaction method.but it is not working. could you please help me in solving the issue.

-(IBAction)sliderval:(id)sender{

   NSSlider *slider=[[NSSlider alloc]init];

   [slider setMinValue:50];

   [slider setMaxValue:100];

   [slider setTarget:self];

   [slider setAction:@selector(sliderDidMove:)];

   [_textField setValue:slider]; 

}

Upvotes: 0

Views: 66

Answers (1)

Nagendra
Nagendra

Reputation: 377

Drag and drop UISlider and UILabel to view in xib. connect IBOutlet to interface variables and IBAction with event 'Value Changed'.


    @interface ViewController ()
    {
        __weak IBOutlet UISlider *slider;
        __weak IBOutlet UILabel *sliderValueLbl;
    }
    @end

    - (IBAction)sliderMoved:(id)sender {
        sliderValueLbl.text = [NSString stringWithFormat:@"%f",slider.value];
    }

Upvotes: 1

Related Questions