我希望得到一些幫助。我以前使用過它,它工作得很好。我試圖用它在一個新的應用程序,它打破了。我知道這是索引問題,但我不能指出它。由於未捕獲的異常'NSRangeException',原因:'*** - [NSMutableArray objectAtIndex:]:index 26超出範圍[0..0]'終止應用程序'
self.greensArray = [NSMutableArray array];
for (int i = 0; i < 26; ++i) {
[self.greensArray addObject:[NSMutableArray array]];
}
letterIndex =[[NSMutableArray alloc] init];
NSMutableArray *name = [searchViewArray valueForKey:@"meatName"];
for (int i = 0; i < [name count]; ++i) {
NSUInteger firstLetter = [ALPHA rangeOfString:[[name objectAtIndex:i ] substringToIndex:1]].location;
[self.greensArray insertObject:[NSMutableArray array] atIndex:i];
if (firstLetter != NSNotFound) {
[[self.greensArray objectAtIndex:firstLetter] addObject:[name objectAtIndex:i]];
}
char alphabet = [[name objectAtIndex:i] characterAtIndex:0];
NSString *uniChar = [NSString stringWithFormat:@"%C",alphabet];
if(![letterIndex containsObject:uniChar])
{
[letterIndex addObject:uniChar];
}
}
firstLetter可能超過25或greensArray的當前界限嗎? – Joe 2011-03-25 20:25:00
什麼行產生崩潰? – TechZen 2011-03-25 20:45:37
這是生成崩潰的代碼 - [[self.beefArray objectAtIndex:firstLetter] addObject:[name objectAtIndex:i]]; – 2011-03-28 20:07:59