有没有一种方法可以通过编程来改变基于计算的UIStepper的值?

问题描述:

比方说,我有3 UIStepper s。
当我更改一个的值时,其他步进器的值将根据公式更改。有没有一种方法可以通过编程来改变基于计算的UIStepper的值?

步进一个值是10。
步进2个值为5
步进3个值为3

如果我改变步进10 +/- 1,它可能会改变在步进值2 +/- 一个。

这可能吗?

这是绝对可能的。

你能想象这样的场景:

UIStepper *stepperOne = [[UIStepper alloc] initWithFrame:frame]; 
[stepperOne addTarget:self action:@selector(stepperOneChanged:) forControlEvents:UIControlEventValueChanged]; 

- (void)stepperOneChanged:(UIStepper*)stepperOne{ 
    //This method would be called on the target of your first stepper on UIControlEventsValueChanged 

    //Decrease the value by 1 
    stepperTwo.value --; 

    //OR 
    //Increase the value by 1 
    stepperTwo.value ++; 
} 
+0

我可以说stepperTwo.value = 10;例如,因为我的测试返回为NULL。 workOutLength = classLength - (warmUpLength + coolDownLength); stepperWorkOutLength.value = workOutLength; (如何在代码中添加代码到回复中,每次我输入时都会更新帖子:( – 2012-03-09 02:37:25

+0

),您可以将它放在两个之间:'什么是返回NULL?是的,您可以将值设置为nay值最小值和最大值 – Zebs 2012-03-09 02:51:26