2010-01-15 4 views
0

J'ai ce codeObtenir erreur Stack, Inexpliqué

-(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"); 


} 

et j'obtenir ce rapport de journal, quand je tape dans le 's, a, m' champ texte

[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] Log Première lettre de tableau: s 2010-01-15 15: 50: 35.399 Flash! [39290: 207] Lettres: 2 2010-01-15 15: 50: 35.400 Flash! [39290: 207] loopedy Boucle 2010-01-15 15: 50: 35.400 Flash! [39290: 207] lettre Chaîne: s 2010-01-15 15: 50: 35.401 Flash! [39290: 207] bouclé boucle 2010-01-15 15: 50: 35.401 Flash! [39290: 207] lettre Chaîne: a 2010-01-15 15: 50: 35.402 Flash! [39290: 207] loopedy Boucle 2010-01-15 15: 50: 35.402 Flash! [39290: 207] lettre Chaîne: m 2010-01-15 15: 50: 35.404 Flash! [39290: 207] loopedy Boucle 2010-01-15 15: 50: 35.405 Flash! [39290: 207] * Fin de l'application en raison d'une exception non interceptée 'NSRangeException', raison: '* - [NSCFArray objectAtIndex:]: index (3) au-delà des limites (3) » 2010-01-15 15: 50: 35,406 flash! [39290: 207] Stack: ( 29287515, 2538743049, 29371451, 29371290 , 478409, 74279, 9945, 2716761, 3124130, 3132867, 3128079, 2821683, 2730012, 2756789, 37383889, 29072256, 29068360, 37377933, 37378130, 2760707, 9228 ,)

et je n'ai aucune idée de ce que je fais mal, donc toute aide est appréciée.

Cheers, Sam

Répondre

0

Vous ne décrémentez runLoopTimes dans la boucle. Donc, il boucle indéfiniment. Et finalement indexTimes est hors de la fin du tableau.

+0

Woops, n'a pas fait ça, non. À la vôtre Anon. –