我會快速的:我有一個iPhone OS 3.1.2的應用程序,它可以減少分數。我有4個網點:分數縮減器應用程序的問題
- oTop和oBottom:兩個UITextFields,代表originalTop和originalBottom。
- rTop和rBottom:兩個UILabels,代表reducedTop和reducedBottom。
這裏是我使用的代碼:
- (IBAction爲)減少{
int numerator = [[oTop text] intValue];
int denominator = [[oBottom text] intValue];
if (denominator > 0) {
NSMutableArray *factors1 = [[NSMutableArray alloc] init];
NSMutableArray *factors2 = [[NSMutableArray alloc] init];
int factors1length;
int factors2length;
for (int i = 1; i < ceil(sqrt(numerator)); i ++) {
[factors1 addObject:[NSString stringWithFormat:@"%@", i]];
if (round(numerator/i) != numerator/i) {
[factors1 removeLastObject];
} else {
factors1length ++;
}
}
for (int i = factors1length; i <= 0; i --) {
[factors1 addObject:[NSString stringWithFormat:@"%@", (numerator/[[factors1 objectAtIndex:i] intValue])]];
} //End get numerator factors
for (int i = 1; i < ceil(sqrt(denominator)); i ++) {
[factors2 addObject:[NSString stringWithFormat:@"%@", i]];
if (round(denominator/i) != denominator/i) {
[factors2 removeLastObject];
} else {
factors2length ++;
}
}
for (int i = factors2length; i <= 0; i --) {
[factors2 addObject:[NSString stringWithFormat:@"%@", (denominator/[[factors2 objectAtIndex:i] intValue])]];
} //End get denominator factors
}
}
很抱歉的雜散線。 無論如何,有人能告訴我發生了什麼事嗎? 當我啓動時,在兩個文本字段中輸入一個大於0的數字,然後按下「減少」按鈕,應用程序崩潰。 請幫幫忙,
HiGuy
編輯:改變了第一和第三從環路(INT I = 0(INT I = 1
感謝您的幫助,但它仍然崩潰。還有更多問題嗎? (除了第三個for循環) – 2010-01-16 18:02:16
您是否曾嘗試在方法開始時設置斷點,逐步執行代碼,查看執行時局部變量的值,並注意它崩潰的行? – cdespinosa 2010-01-16 23:19:03
不知道你是否已經在遵循cdespinosa的好建議之後解決了這個問題,但我很快就會在代碼中發現更多問題。 – DyingCactus 2010-01-17 03:29:17