是否可以为3个文本框设置1个计算按钮,或者每个文本框都需要一个按钮,文本框是,桶,加仑和升,如果我在桶中放入10个我希望按钮计算加仑和升10桶是多少。同样,如果我把10英寸放在升数盒子里,我希望按钮能够计算出多少桶和加仑。 这是我现在的代码:
- (IBAction)Calculate:(id)sender {
NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
float a = [[numberFormatter numberFromString:_Barrels.text] floatValue];
float b = [[numberFormatter numberFromString:_Gallons.text] floatValue];
float c = [[numberFormatter numberFromString:_Liters.text] floatValue];
_Barrels.text = [[NSString alloc]initWithFormat:@"% .2f", a];
_Gallons.text = [[NSString alloc]initWithFormat:@"% .2f", a * 42];
_Liters.text = [[NSString alloc]initWithFormat:@"% .2f", a * 159];
_Barrels.text = [[NSString alloc]initWithFormat:@"% .2f", b * .0238];
_Gallons.text = [[NSString alloc]initWithFormat:@"% .2f", b];
_Liters.text = [[NSString alloc]initWithFormat:@"% .2f", b * 3.785];
_Barrels.text = [[NSString alloc]initWithFormat:@"% .2f", c * .0063];
_Gallons.text = [[NSString alloc]initWithFormat:@"% .2f", c * .264];
_Liters.text = [[NSString alloc]initWithFormat:@"% .2f", c];
switch ([sender tag]) {
case 1:
[_Barrels resignFirstResponder];
[_Gallons resignFirstResponder];
[_Liters resignFirstResponder];
break;
default:
break;
}
答案 0 :(得分:0)
当然,您可以使用一个按钮来完成所有这三项操作。唯一困难的部分是跟踪用户输入值的bos。