-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 のサブクラスにしたことです。コードはほぼ同じでした。2 番目のビュー コントローラーで配列を初期化する必要はありませんでした。

すべてが機能しています。助けてくれてどうもありがとう。

于 2013-12-17T11:27:36.590 に答える