确定在 UIStepper 中是否按下了加号或减号按钮我使用以下方法:
- (void)stepperOneChanged:(UIStepper*)stepperOne
而我比较stepperOne.value
全局值保存在我的 TableView 类中。
我认为这不是正确的方法。
因此,为了澄清这一点,我将展示我正在使用的“坏”代码:
- (void)stepperOneChanged:(UIStepper*)stepperOne
{
BOOL PlusButtonPressed=NO;
if(stepperOne.value>globalValue)
{
PlusButtonPressed =YES;
}
globalValue=stepperOne.value;
//do what you need to do with the PlusButtonPressed boolean
}
那么这样做的正确方法是什么? (无需保存全局变量)
这是识别 UIStepper 是否单击“+”或单击“-”的简单且简短的方法
//First You have to declare oldValue as an int (or long/float/NSInteger etc. etc.) in Header File
//So that you can access globally to that particular implementation file
- (void)viewDidLoad
{
[super viewDidLoad];
oldValue=stepperObj.value;
}
- (IBAction)stepperStep:(id)sender
{
if (stepperObj.value>oldValue) {
oldValue=oldValue+1;
//Your Code You Wanted To Perform On Increment
}
else {
oldValue=oldValue-1;
//Your Code You Wanted To Perform On Decrement
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)