我试图让我的应用程序在UISwitch设置为“开”位置时运行一个数学公式,而在其设置为“关”位置时运行另一个数学公式。
我正在尝试这样布置:
如果switch = on,则[第一个公式]
如果开关=关闭,则[第二个公式]
我该如何编码?
=============
编辑:
这是我当前尝试对其进行编码的方式。
-(IBAction)switchValueChanged:(UISwitch *)sender
{
if(sender.on)
{
-(float)conver2inches: (NSString *)mmeters {
return [mmeters floatValue]/25.4f;
}
-(IBAction)calculate:(id)sender{
float answer = [self conver2inches:entry.text];
output.text=[NSString stringWithFormat:@"%f",answer];}}
else{
-(float)conver2mmeters:(NSString *)inches {
return [inches floatValue]*25.4f;
}
-(IBAction)calculate:(id)sender{
float answer = [self conver2mmeters:entry.text];
output.text=[NSString stringWithFormat:@"%f",answer];
}}
}
最佳答案
您需要连接一个类似于uiswitch的值更改后的uievent的函数。
-(IBAction) switchValueChanged:(UISwitch *) sender
{
if(sender.on)
{
...
}
else
{
...
}
}
关于iphone - 在xcode中使用UISwitch的If/Then语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15892278/