我的数组已填充,但我仍然得到错误:索引0超出空数组的边界'

时间:2013-12-16 23:42:24

标签: ios objective-c uitableview parse-platform pfquery

我已经尝试了很多选项来解决这个问题,似乎很多人都得到了同样的错误,但我已经尝试了一些答案,但无法修复。

这就是我调用第二个PFQueryTableViewConttoller的方法:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    ExerciciosViewController *exercicios = [sb   instantiateViewControllerWithIdentifier:@"ExerciciosViewController"];

    [super tableView:tableView didSelectRowAtIndexPath:indexPath];

    if ([[_seriesForDisplay objectAtIndex:indexPath.row] isEqualToString:@"Serie A"]) {
        [exercicios setTitle:[_seriesForDisplay objectAtIndex:indexPath.row]];
        NSLog(@"Serie A");
        exercicios.exerciciosArray = _seriesArray;
    }
    if ([[_seriesForDisplay objectAtIndex:indexPath.row] isEqualToString:@"Serie B"]) {
        [exercicios setTitle:[_seriesForDisplay objectAtIndex:indexPath.row]];
        NSLog(@"Serie B");
    }
    if ([[_seriesForDisplay objectAtIndex:indexPath.row] isEqualToString:@"Serie C"]) {
        [exercicios setTitle:[_seriesForDisplay objectAtIndex:indexPath.row]];
        NSLog(@"Serie C");
    }

    [self.navigationController pushViewController:exercicios animated:YES];
}

现在,当我点击第一个选项,即意甲时,它需要我第二个PFQueryTableViewController,当方法NumberofRowsInSection不存在(注释)时,My TableView显示两个具有以下代码的项目,尽管我的数组有4个物品,它应该显示四个。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath object:(PFObject *)object {
    static NSString *CellIdentifier = @"Cell";

    PFTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[PFTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
    }

    PFObject *o = _exerciciosArray[indexPath.row];
    PFObject *object2 = o[@"exercicio"];
    cell.textLabel.text = object2[@"titulo"];

    PFFile *thumbnail = object2[@"foto"];
    cell.imageView.file = thumbnail;


    cell.textLabel.numberOfLines = 2;
    // Colors
    cell.backgroundColor = [UIColor blackColor];
    cell.textLabel.textColor = [UIColor whiteColor];


    return cell;

}

当我插入方法NumberOfRowsInSection:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _exerciciosArray.count;
}

如果我在那里放一个Log,它会显示填充了4个项目的数组。虽然使用上面的代码我会收到消息:[__NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array'

我尝试过很多东西,但似乎没什么用。

感谢任何帮助。感谢。

1 个答案:

答案 0 :(得分:0)

我不确定发生了什么,我尝试了很多东西。我做的是,而不是让我的类成为PFQueryTableViewController(parse.com)的子类,我只是使它成为UITableViewController的子类。代码几乎相同。没有必要在第二个视图控制器中分配init数组。

现在一切正常。非常感谢您的帮助。