UISwitch が「オン」の位置に設定されているときにアプリで 1 つの数式を実行し、「オフ」の位置に設定されているときに別の数式を実行しようとしています。
私はそれを次のようにレイアウトしようとしています:
if switch = on, then [最初の数式]
スイッチ = オフの場合、[第 2 式]
これをどのようにコーディングしますか?
=============
編集:
これは私が現在コーディングしようとしている方法です。
-(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];
}}
}