开发者

UISlider's value changes to values outside of range

I am trying to implement a UISlider that has a minimum of 1 and a maximum of 10. I set up an IBOutlet for the slider and an IBAction for when the slider's value changes. Here is my code:

//scale is the slider, and scaleValue is a label that displays the slider's value.
- (IBAction)scaleChanged
{
    scaleValue.text = [NSString stringWithFormat:@"%d", scale.value];
    NSLog(scaleValue.text);
}

The problem is what NSLog gives me:

[Session started at 2011-07-25 20:36:22 -0700.]
2011-07-25 20:36:25.626 LineModel[1672:207] 0
2011-07-25 20:36:25.861 LineModel[1672:207] 0
2011-07-25 20:36:25.877 LineModel[1672:207] 0
2011-07-25 20:36:25.894 LineModel[1672:207] -536870912
2011-07-25 20:36:25.911 LineModel[1672:207] -536870912
2011-07-25 20:36:25.928 LineModel[1672:207] -1073741824
2011-07-25 20:36:25.944 LineModel[1672:207] 1610612736
2011-07-25 20:36:25.961 LineModel[1672:207] 1073741824
2011-07-25 20:36:25.978 LineModel[1672:207] 1073741824
2011-07-25 20:36:25.994 LineModel[1672:207] 1073741824
2011-07-25 20:36:26.011 LineModel[1672:207] 1073741824
2011-07-25 20:36:26.028 LineModel[1672:207] -2147483648
2011-07-25 20:36:26.044 LineModel[1672:207] 0
2011-07-25 2开发者_如何学JAVA0:36:26.061 LineModel[1672:207] -2147483648

You get the idea. Now, I know the slider's value is a float and not an integer, but the strange thing is that it was actually working fine before, when I had the maximum set instead at 50. Now, though, even if I set the maximum back to 50, it still prints this out. What is going on?


your NSLog is not following the right syntax, write like this

 NSLog(@"%@",scaleValue.text);

instead NSLog(scaleValue.text);

Try this

- (IBAction)scaleChanged
{
    scaleValue.text = [NSString stringWithFormat:@"%.2f", scale.value];
    NSLog(scaleValue.text);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜