我正在尝试实现一个至少为1且最多为10的UISlider。我为滑块设置了一个IBOutlet,并为滑块的值更改时设置了IBAction。这是我的代码:
//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);
}
问题是NSLog给我的:
[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 20:36:26.061 LineModel[1672:207] -2147483648
你明白了。现在,我知道滑块的值是一个浮点而不是一个整数,但奇怪的是它实际上工作正常之前,当我将最大值设置为50时。但是,即使我将最大值设置为50,它仍然打印出来。发生了什么事?
答案 0 :(得分:0)
你的NSLog没有遵循正确的语法,写得像这样
NSLog(@"%@",scaleValue.text);
代替NSLog(scaleValue.text);
试试这个
- (IBAction)scaleChanged
{
scaleValue.text = [NSString stringWithFormat:@"%.2f", scale.value];
NSLog(scaleValue.text);
}