簡體   English   中英

獲取堆棧錯誤,原因不明

[英]Getting Stack Error, Unexplained

我有這個代碼

-(IBAction) generateFlashNow:(id)sender{

[textField resignFirstResponder];
NSString *string1 = textField.text;
//NSString *string2 = [string1 stringByReplacingOccurrencesOfString:@"" withString:@","];
NSArray *arrayOfLetters = [string1 componentsSeparatedByString:@","];

NSLog(@"Log Array :%@", arrayOfLetters);

//NSArray *imageArray = [[NSArray alloc] init];

NSLog(@"Log First Letter of array: %@",[arrayOfLetters objectAtIndex:0]);

runLoopTimes = [arrayOfLetters count];
runLoopTimes = (runLoopTimes -1);
NSLog(@"Letters:%d", runLoopTimes);

int timesThroughLoop;

while (runLoopTimes > 0) {
    NSLog(@"loopedy Loop");

    NSString *LetterString = [NSString stringWithFormat:@"%@", [arrayOfLetters objectAtIndex:indexTimes]];
    timesThroughLoop --;
    NSLog(@"letter String : %@", LetterString);
    indexTimes ++;

    if (runLoopTimes == 0) {
        return; 
    }
}

NSLog(@"done");


}

當我在文本字段“ s,a,m”中鍵入內容時,我得到此日志報告

[Session started at 2010-01-15 15:50:30 +1300.]
2010-01-15 15:50:35.398 Flash![39290:207] Log Array :(
s,
a,
m

)2010-01-15 15:50:35.399 Flash![39290:207]記錄數組的第一個字母:s 2010-01-15 15:50:35.399 Flash![39290:207] Letters:2 2010-01-15 15:50:35.400 Flash![39290:207] loopedy循環2010-01-15 15:50:35.400 Flash![39290:207]字母字符串:s 2010-01-15 15:50:35.401 Flash![39290: 207] loopedy Loop 2010-01-15 15:50:35.401 Flash![39290:207] letter字符串:a 2010-01-15 15:50:35.402 Flash![39290:207] loopedy Loop 2010-01-15 15 :50:35.402 Flash![39290:207]字母字符串:m 2010-01-15 15:50:35.404 Flash![39290:207] loopedy Loop 2010-01-15 15:50:35.405 Flash![39290:207 ] *由於未捕獲的異常'NSRangeException'而終止應用程序,原因:'* -[NSCFArray objectAtIndex:]:超出范圍(3)的索引(3)'2010-01-15 15:50:35.406 Flash![39290:207]堆棧:(29287515,2538743049,29371451,29371290,478409,74279,9945,2716761,3124130,3132867,3128079,2821683,2730012,2756789,37383889,29072256,29068360,37377933,37378130,2760707,9228,9082)

而且我不知道我在做什么錯,因此我們將不勝感激。

干杯,山姆

您永遠不會減少runLoopTimes內的runLoopTimes 因此它將無限期地循環。 最終indexTimes不在數組的末尾。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM