UITableView在NSArray索引1上崩溃,超出了界限



我的表不断崩溃。"索引1超出界限"。我返回该部分中行数的数组计数,但一旦滚动到第二行(索引1),应用程序就会崩溃。

我有两部分。一个具有设定行数,第二个部分是基于数组中的项数动态创建的。

有什么想法吗?

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
          return 2; //two seperate areas
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
        if (section == 0) {
            return 16; 
        } else {
            NSLog(@"Section: %ld, NumberOfRows: %lu", (long)section, (unsigned long)[self.arrImages count]);
            return [self.arrImages count]; 
        }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = nil;
    NSUInteger section = [indexPath section];
    NSUInteger row = [indexPath row];

        switch (section) {
            case 0:
                 cell =  [super tableView:tableView  cellForRowAtIndexPath:indexPath];
                break;
            case 1:
                cell = [tableView dequeueReusableCellWithIdentifier:@"cellPhoto"];
                if (cell == nil) {
                    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cellPhoto"];
                }
                NSLog(@"Row: %lun%@", (unsigned long)row, [[self.arrImages objectAtIndex:row] objectForKey:@"imageThumbnailURL"]);
                cell.imageView.image = [self imageFromURL:[[self.arrImages objectAtIndex:row] objectForKey:@"imageThumbnailURL"]  fromCache:YES];
                NSLog(@"completed");
                break;
        }

    return cell;
}
#pragma mark UITableViewDelegate methods
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    NSUInteger section = [indexPath section];
    [self doneData];
        switch (section) {
            case 1:
                [tableView deselectRowAtIndexPath:indexPath animated:YES];
                [self performSegueWithIdentifier:@"segue_showphoto" sender:self];
                break;
       }
}

这是我的故障日志

2015-02-12 19:32:51.817 Tops[17236:5681531] Row: 0
https://somethinghere.jpeg
2015-02-12 19:32:51.825 Tops[17236:5681531] completed
2015-02-12 19:32:51.855 Tops[17236:5681531] Row: 1
https://somthinghere.jpeg
2015-02-12 19:32:51.856 Tops[17236:5681531] completed
2015-02-12 19:32:51.862 Tops[17236:5681531] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayI objectAtIndex:]: index 1 beyond bounds [0 .. 0]'

我缺少的实现是:

-(NSInteger)tableView:(UITableView *)tableView indentationLevelForRowAtIndexPath:(NSIndexPath *)indexPath { 
return 0; 
}

最新更新