0

Hello : Im developping an application and I'd like to display the value of a UISlider as the user moove it along the bar.

I created an IBOutlet linked in Interface Builder to an UILabel and a IBAction linked in Interface Builder to the slider. They are declared as following in the Information.h :

@property(nonatomic, retain) IBOutlet UILabel *DispTemp;
@property(nonatomic, retain) IBOutlet UISlider *SetTemperature;

-(IBAction) DisplayTemp:(id) sender;

I didnt forget the @synthesize DispTemp; and @synthesize SetTemperature; in the Information.m .I'm using this code for the IBAction :

-(IBAction) DisplayTemp:(id) sender{
    self.DispTemp.text = [NSString stringWithFormat:@"%d",self.SetTemperature.value];
}

Obviously the Link with interface builder is working because as i moove the slider the value changes. However i set the range from -10 to 30 with a 0,5 step but the value that are shown moove from -a few millions to +a few million and come back regularly to 0. I dont know what is going on, any help would be great. Thanks

WizLiz
  • 2,068
  • 5
  • 25
  • 39

1 Answers1

3

You used a wrong format specifier (%d is for int). The value property of sliders has type float:

self.DispTemp.text = [NSString stringWithFormat:@"%f",self.SetTemperature.value];
Nikolai Ruhe
  • 81,520
  • 17
  • 180
  • 200