2011-12-20 6 views
0

私はUITextFieldを2つ持っています。最初のテキストフィールドはpersonBMIと呼ばれ、数字が表示されます。 2番目はgaugeWeightです。私gaugeWeightフィールドが値よりも(例えば、20-24)、以上両者の値に、personBMIUITextField値未満であるか否かに基づいて単語を表現したいです。テキストフィールドの値を別のフィールドの値に依存して設定する

私はこれを知っていますif/thenステートメントは私のIBActionの一部として表現されているはずです。 gaugeWeightフィールドがpersonBMIフィールドの結果を定義する単語を、それよりも小さいか、それよりも大きいか、またはより大きい値に基づいて表現するために、どのようにコード化しますか?このような

+0

これまでに試したことはありますか? IBAction)を計算:-(次のように –

答えて

1

何かがスタートだろう...

CGFloat bmi = [self.personBMI intValue]; 
NSString *classification = @"Unclassified"; 

if (bmi <= 16.0f) { 
    classification = @"Severely underweight"; 
} else if (bmi <= 18.5f) { 
    classification = @"Underweight"; 
} // the rest 

self.gaugeWeight.text = classification; 
+0

マイIBActionは、(ID)、送信者{ フロートfloatPersonBMI = [personWeight.textに従ってFloatValue] * 703 /([personH​​eight.textに従ってFloatValue] * [personH​​eight.textに従ってFloatValue])。 NSString * stringPersonBMI = [[NSString alloc] initWithFormat:@ "%f"、floatPersonBMI]; personBMI.text = stringPersonBMI; .....そのIBActionに基づいて "if、then"を作成して、上記の "severe underweight"および "underweight"と同様の別のUITextFieldのテキストを返したいとします。 – user1102622

0
#import "ViewController.h" 

@interface ViewController()<UITextFieldDelegate> 
@property (weak, nonatomic) IBOutlet UITextField *personBMI; 
@property (weak, nonatomic) IBOutlet UITextField *gaugeWeight; 
@end 

@implementation ViewController 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    self.personBMI.delegate = self; 
    [self.personBMI addTarget:self action:@selector(textFieldDidChange) forControlEvents:UIControlEventValueChanged]; 
} 

- (void)didReceiveMemoryWarning 
{ 
    [super didReceiveMemoryWarning]; 
    // Dispose of any resources that can be recreated. 
} 

-(void)textfieldDIdChange{ 
    if ([self.personBMI.text floatValue]< 20 && [self.personBMI.text floatValue] > 24) { 
     self.gaugeWeight.text = @"Put some text here"; 
    } 
} 

@end 

は、この情報がお役に立てば幸いです。

関連する問題