Objective c 在视图控制器之间减去浮点值
这是ViewControllerOne:Objective c 在视图控制器之间减去浮点值,objective-c,calculator,subtraction,Objective C,Calculator,Subtraction,这是ViewControllerOne: - (IBAction)total { float a = ([textfield1.text floatValue]); float b = ([textfield2.text floatValue]); float c = ([textfield3.text floatValue]); float d = ([textfield4.text floatValue]); float e = ([textfield5.text floatValue])
- (IBAction)total {
float a = ([textfield1.text floatValue]);
float b = ([textfield2.text floatValue]);
float c = ([textfield3.text floatValue]);
float d = ([textfield4.text floatValue]);
float e = ([textfield5.text floatValue]);
float f = a+b+c+d+e+([textfield6.text floatValue]);
total.text = [[NSString alloc] initWithFormat:@"$%.2f", f];
这是视图控制器两个:
float g = ([textfield1.text floatValue]);
float h = ([textfield2.text floatValue]);
float i = ([textfield3.text floatValue]);
float j = ([textfield4.text floatValue]);
float k = ([textfield5.text floatValue]);
float l = a+b+c+d+e+([textfield6.text floatValue]);
totalTwo.text = [[NSString alloc] initWithFormat:@"$%.2f", l];
在ViewControllerThree中,我想用ViewControllerTo的和减去ViewControllerOne的和,并在标签中显示答案 在
appDelegate
中存储sumtotal.text
和totalTwo.text
的值
在AppDelegate.h文件中
float totalOne, totalTwo;
@propery(nonatomic)float totalOne, totalTwo;
在AppDelgate.m文件中
@synthesize totalOne, totalTwo;
- (IBAction)total
{
//Create the instance of appDelegate as
AppDelegate *app = (AppDelegate *)[[UIApplication sharedApplication] delegate];
float a = ([textfield1.text floatValue]);
float b = ([textfield2.text floatValue]);
float c = ([textfield3.text floatValue]);
float d = ([textfield4.text floatValue]);
float e = ([textfield5.text floatValue]);
float f = a+b+c+d+e+([textfield6.text floatValue]);
app.totalOne = f;
total.text = [[NSString alloc] initWithFormat:@"$%.2f", f];
}
//Create the instance of appDelegate as
AppDelegate *app = (AppDelegate *)[[UIApplication sharedApplication] delegate];
float g = ([textfield1.text floatValue]);
float h = ([textfield2.text floatValue]);
float i = ([textfield3.text floatValue]);
float j = ([textfield4.text floatValue]);
float k = ([textfield5.text floatValue]);
float l = a+b+c+d+e+([textfield6.text floatValue]);
app.totalTwo = l;
totalTwo.text = [[NSString alloc] initWithFormat:@"$%.2f", l];
-(IBAction)btnCalculate
{
//Create the instance of appDelegate as
AppDelegate *app = (AppDelegate *)[[UIApplication sharedApplication] delegate];
totalthree = app.totalOne - app.totalTwo;
lbl.text = [NSString StringWithFormat:@"$%.2f", totalThree];
}
如何将总和存储在AppDelegate中?作为floattotalone和floattotaltwo?谢谢,这有助于我完成。关于最后一个问题,我想要'totalthree=app.totalOne-app.totalTwo;'使用-(iAction)计算在“label3”上显示。单击按钮时如何显示此总和?我感谢你的帮助