0

我在通过导航控制器运行时保存外部变量时遇到问题,这是一个应用程序,我在这里计算游戏点数,我的代码用于计算点数:

这是用于计算点数的 IBAction:

- (IBAction)RedTeloBallsTotal:(id)sender {

NSString *firstString = RedTeloBallsOne.text;
NSString *secondString = RedTeloBallsTwo.text;
NSString *thirdString = RedTeloBallsThree.text;
NSString *fourthString = RedTeloBallsFour.text;

NSString *LEGAL = @"0123456789";
NSCharacterSet *characterSet = [[NSCharacterSet characterSetWithCharactersInString:LEGAL] invertedSet];
NSString *filteredOne = [[firstString componentsSeparatedByCharactersInSet:characterSet] 
                         componentsJoinedByString:@""];
NSString *filteredTwo = [[secondString componentsSeparatedByCharactersInSet:characterSet] 
                         componentsJoinedByString:@""];
NSString *filteredThree = [[thirdString componentsSeparatedByCharactersInSet:characterSet] 
                           componentsJoinedByString:@""];
NSString *filteredFour = [[fourthString componentsSeparatedByCharactersInSet:characterSet] 
                          componentsJoinedByString:@""];

firstString = filteredOne;
secondString = filteredTwo;
thirdString = filteredThree;
fourthString = filteredFour;

//Here we are creating three doubles
double num1;
double num2;
double num3;
double num4;
double output;
//Here we are assigning the values 
num1 = [firstString doubleValue];
num2 = [secondString doubleValue];
num3 = [thirdString doubleValue];
num4 = [fourthString doubleValue];

output = num2 + (num1 * 2) + num4 + (num3 * 25);

//Now we are going to display the output in the label.
RedTeloBallsTotal.text = [NSString stringWithFormat:@"%.0f",output];


}
4

1 回答 1

0

要保存计算的值,您应该在对象中为其创建一个声明的属性。

例如,在此对象的标题中,将其与其他属性一起添加:

@property (nonatomic, assign) double redTeloBallsTotalOutput;

然后,在实现文件(.m 文件)的顶部,您应该会看到其他 @synthesize 行,添加以下行:

@synthesize redTeloBallsTotalOutput;

为了在上面的函数中设置值,请使用:

self.redTeloBallsTotalOutput = output;

最后,要在此对象的其他位置使用它,请使用:

self.redTeloBallsTotalOutput
于 2012-04-05T03:58:34.653 回答