-1

I've tried a lot of options to solve this, and it seems that a lot of people get the same error, but I've tried some answers but couldn't fix.

This is how I call my second 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];
}

Now, When I click the first option, which is Serie A, it takes me to second PFQueryTableViewController, and when method NumberofRowsInSection is not present (commented), My TableView shows two items with the following code, although my array has 4 items and it should show four.

- (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;

}

When I insert the method NumberOfRowsInSection:

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

If i put a Log there, it shows array populated with 4 items. Although with the above code I get crash with message: [__NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array'

I have tried a lot of things, but nothing seems to work.

Any help is appreciated. Thanks.

4

1 回答 1

0

我不确定发生了什么,我已经尝试了很多东西。我所做的是,我没有将我的类设为 PFQueryTableViewController (parse.com) 的子类,而是将其设为 UITableViewController 的子类。代码几乎相同。不必在第二个视图控制器中分配初始化数组。

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

于 2013-12-17T11:27:36.590 回答