在NSArray上调用objectAtIndex时出现NSRangeException

时间:2013-02-06 16:18:52

标签: objective-c nsarray indexoutofboundsexception

我收到此错误,我不明白为什么:

  

* 由于未捕获的异常'NSRangeException'而终止应用程序,原因:' - [__ NSCFArray objectAtIndex]:索引(171053968)超出范围(226)'

- (void)makeArrayOfGrade{

    BOOL *alreadyAdded;
    for (int a = 0; a <= [allData count]-1; a++) {
        NSIndexPath *path = [NSIndexPath indexPathForRow:a inSection:0];
        NSDictionary *dict = [allData objectAtIndex:path];

        if ([[dict objectForKey:@"grade"] isEqualToString: @"5 класс"]) {

            /*     for (int i = 0; i <= [allData count]; i++){
             NSIndexPath *inPath = [NSIndexPath indexPathForRow:i inSection:0];
             NSDictionary *inDict = [allData objectAtIndex:path];
             if ([dict objectForKey:@"subject"]==[inDict objectForKey:@"subject"]) {
             added=YES;
             }
             }
             }
             if (added==NO) { */
            [dataForEachGrade addObject:dict];
            NSLog(@"added");

        }
    }
}

1 个答案:

答案 0 :(得分:1)

问题可能是您在不存在的索引处请求allData的对象。 即,表格视图中的数据不适合allData