I am quite new to Xcode and I am having trouble placing the value of a slider in a label when the slider is value is changed.
Here is my code: Header file:
@interface ViewTwoViewController : UIViewController
{
IBOutlet UISlider *slider;
IBOutlet UILabel *sliderLabel;
}
-(IBAction)sliderValue:(id)sender;
and here is my m file:
-(IBAction)sliderValue:(UISlider *)sender {
sliderLabel.text = [NSString stringWithFormat:@"%g", slider.value];
}
I am not 100% sure why the value isn't updating?
I am looking forward to hearing from you all!
Here's an XCode project that does what you're looking for: http://clrk.it/013r203C1y1F
Note that:
UIViewController
as
IBOutlets in the storyboard.valueChanged
: method is linked to the UIViewController
in the storyboard.%f
.Your method would look something like this:
-(IBAction)sliderValueChanged:(id)sender
{
if (sender == _slider) {
_label.text = [NSString stringWithFormat:@"%0.3f", _slider.value];
}
}