0

这是 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]);
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 中,我想用 ViewControllerTwo 的总和减去 ViewControllerOne 的总和,并在标签中显示答案。

4

1 回答 1

0

存储 sum total.text& totalTwo.textin appDelegatelike

在 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];
}
于 2013-02-20T04:35:15.673 回答