[英]Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSMutableArray objectAtIndex:]: index 26 beyond bounds [0 .. 0]'
I would appreciate some help. 我将不胜感激。 I have used this before and it worked fine.
我以前使用过它,并且效果很好。 I tried to use it in a new app and it breaks.
我试图在新应用中使用它,但它坏了。 I understand it is a problem with the index, but I can't pin point it.
我知道索引存在问题,但我无法指出。
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];
}
}
The problem was here: [self.greensArray insertObject:[NSMutableArray array] atIndex:i]; 问题出在这里:[self.greensArray insertObject:[NSMutableArray array] atIndex:i]; I don't know why this worked in my first application, but this line of code added additional values to the greensArray.
我不知道为什么这在我的第一个应用程序中有效,但是这一行代码为greensArray添加了附加值。 That threw off the integer / meatName count and made the whole app crash.
那扔掉了整数/ meatName计数,并使整个应用程序崩溃。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.