我有两个UITextField
个。第一个文本字段称为personBMI
并表示一个数字。第二个是gaugeWeight
。我希望我的gaugeWeight
字段根据personBMI
UITextField
是否小于值,介于两个值(例如,20-24)之间或大于值来表达单词。
我知道if
/ then
语句应该表示为IBAction
的一部分。我如何编码我的gaugeWeight
字段来表达定义personBMI
字段结果的字词,因为它小于,介于或大于某个值?
答案 0 :(得分: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;
答案 1 :(得分: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
希望这有帮助。