Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/117.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 根据另一个字段的值设置文本字段的值_Objective C_Ios_Cocoa Touch_Uitextfield - Fatal编程技术网

Objective c 根据另一个字段的值设置文本字段的值

Objective c 根据另一个字段的值设置文本字段的值,objective-c,ios,cocoa-touch,uitextfield,Objective C,Ios,Cocoa Touch,Uitextfield,我有两个UITextFields。第一个文本字段称为personBMI,表示一个数字。第二个是gaugeWeight。我希望我的gaugeewight字段根据personBMIUITextField是小于一个值、介于两个值之间(例如20-24)还是大于一个值来表示一个单词 我知道这个如果/那么语句应该作为我的iAction的一部分来表达。基于personBMI字段小于、介于或大于一个值,我如何为我的gaugewight字段编码以表示定义该字段结果的单词?类似的内容将是一个开始 CGFloat b

我有两个
UITextField
s。第一个文本字段称为
personBMI
,表示一个数字。第二个是
gaugeWeight
。我希望我的
gaugeewight
字段根据
personBMI
UITextField
是小于一个值、介于两个值之间(例如20-24)还是大于一个值来表示一个单词


我知道这个
如果
/
那么
语句应该作为我的
iAction
的一部分来表达。基于
personBMI
字段小于、介于或大于一个值,我如何为我的
gaugewight
字段编码以表示定义该字段结果的单词?

类似的内容将是一个开始

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;
CGFloat bmi=[self.personBMI intValue];
NSString*分类=@“未分类”;
如果(bmi
#导入“ViewController.h”
@界面视图控制器()
@属性(弱、非原子)IbUitextField*personBMI;
@性质(弱、非原子)IbUitextField*GaugeWight;
@结束
@实现视图控制器
-(无效)viewDidLoad
{
[超级视图下载];
self.personBMI.delegate=self;
[self.personBMI addTarget:self action:@selector(textfielddichange)for controlEvents:UIControlEventValueChanged];
}
-(无效)未收到记忆警告
{
[超级记忆警告];
//处置所有可以重新创建的资源。
}
-(无效)文本字段更改{
如果([self.personBMI.text floatValue]<20&[self.personBMI.text floatValue]>24){
self.gaugeewight.text=@“在此处放置一些文本”;
}
}
@结束

希望这能有所帮助。

到目前为止您尝试过什么吗?我的iAction如下:-(iAction)calculate:(id)sender{float floatPersonBMI=[personWeight.text floatValue]*703/([personHeight.text floatValue]*[personHeight.text floatValue]);NSString*stringPersonBMI=[NSString alloc]initWithFormat:@“%f”,floatPersonBMI];personBMI.text=stringPersonBMI;……因此,我想根据iAction生成一个“if,then”,在另一个UITextField中返回文本,类似于上面提到的“严重体重不足”和“体重不足”
#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