我对 objective-c 真的很陌生,我在文本字段及其值方面遇到了一些问题。我的ViewController中有两个TextField。有了这些TextField,我试图获得用户的体重和身高,并计算他们的体重指数。我已经在android中编写了以下代码,并尝试将其转换为 objective-c 。
valueWeight = Double.parseDouble(edit_txt_weight.getText().toString());
valueHeight = Double.parseDouble(edit_txt_height.getText().toString());
resulBMI = (valueWeight / (valueHeight * valueHeight)*10000);
txt_vki_resultText.setText(new DecimalFormat("##.##").format(resulBMI)+"");
我的问题是;
- (IBAction)btnCalculate:(id)sender {NSString *weight = self.editTextKg.text;NSString *height = self.editTextHeight.text;}
最佳答案
- (IBAction)btnCalculate:(id)sender {
double weight = [ self.editTextKg.text doubleValue]
double height = [ self.editTextHeight.text doubleValue];
double resulBMI = (valueWeight / (valueHeight * valueHeight)*10000);
txt_vki_resultText.text = [NSString stringWithFormat:@"%.2f",resulBMI];
}