本文介绍了如何使用UIStepper的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用 UIStepper
来增加或减少一个整数
,但 - 和+都会增加整数!如何识别+和 - 按钮?
I am trying to work with UIStepper
to increment or decrement an integer,but both "-" and "+" increase the integer! How can I recognize the "+" and "-" button?
在 UIStepper
头文件中有两个 UIButton
s:
In the UIStepper
header file there are two UIButton
s:
UIButton *_plusButton;
UIButton *_minusButton;
例如:
- (IBAction)changeValue:(id)sender
{
UIStepper *stepper = (UIStepper *) sender;
stepper.maximumValue = 10;
stepper.minimumValue = 0;
if (stepper)
{
integer++;
[label setText:[NSString stringWithFormat:@"%d",integer]];
}
else
{
integer--;
[label setText:[NSString stringWithFormat:@"%d",integer]];
}
}
推荐答案
你应该忽略ivars。他们不会帮助你。
You should ignore the ivars. They will not help you.
UIStepper
的值
属性,您可以查询以确定当前值是什么。因此,您的方法可能只是:
The UIStepper
has a value
property that you can query to figure out what the current value is. So your method could simply be:
- (IBAction)valueChanged:(UIStepper *)sender {
double value = [sender value];
[label setText:[NSString stringWithFormat:@"%d", (int)value]];
}
这篇关于如何使用UIStepper的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!