我在 xcode 中有一个例程,它调用一个函数并将结果吐出到 iPhone 应用程序上的 UITextView 元素。
在例程开始之前,我想重置所有 NSString 对象/值以及我用来计算结果的任何变量。有没有快速的方法来做到这一点?
到目前为止,无论我在 UITextField 中重新输入什么,它都会在初始计算后被忽略。
解决按钮的代码:-
- (IBAction)Solve:(id)sender {
//
// Reset strings and variable code here
//
[_Number1 resignFirstResponder];
[_Number2 resignFirstResponder];
[_Number3 resignFirstResponder];
[_Number4 resignFirstResponder];
[_Number5 resignFirstResponder];
[_Number6 resignFirstResponder];
[_TargetNum resignFirstResponder];
// Dismiss Keyboard
int numb1,numb2,numb3,numb4,numb5,numb6,numTar;
numb1 = [self.Number1.text intValue];
numb2 = [self.Number2.text intValue];
numb3 = [self.Number3.text intValue];
numb4 = [self.Number4.text intValue];
numb5 = [self.Number5.text intValue];
numb6 = [self.Number6.text intValue];
numTar = [self.TargetNum.text intValue];
mainLoopOne(numb1,numb2,numb3,numb4,numb5,numb6,numTar);
// Start calculation with field values
readAnswers = @"Please read answers bottom-up.\n";
cantCalc = NULL;
finalResult = @"";
if (numb1 != 0) {
int ii;
for(ii = 0; ii < 6 ; ii++) {
if (allAnswers[ii] != NULL) {
finalResult = [finalResult stringByAppendingFormat:@"%@", allAnswers[ii]];
}
}
if (finalResult == NULL) {
cantCalc = @"Unfortunately, that doesn't seem to be possible, as there was no answer calculated.\n";
readAnswers = @"";
}
CompileText = [NSString stringWithFormat:@"%@\n%@\nfrom %d combination tries.", readAnswers, finalResult, countCombi];
[self.TextWin setText:CompileText];
}
countCombi = 0;
}
@end
大多数字符串和变量都设置在 #import "ViewController.h" 下,因此它们是全局的:-
NSString *readAnswers;
NSString *cantCalc;
NSString *finalResult;
NSString *allAnswers[10];
NSString *CompileText;
NSString *readAnswers;
NSString *finalResult;
#define DIV 0
#define MUL 1
#define ADD 2
#define SUB 3
int n1,n2,n3,n4,n5,n6;
int answer_counter = 0;
int tar2 = 0;
int number[6];
int target = 0;
int used[6];
int countCombi;
谢谢。