0

ここで何が起こっているのか理解できません...

    -(void)viewWillAppear:(BOOL)animated
{
    NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
    NSEntityDescription *entity = [ NSEntityDescription entityForName:kTransaction inManagedObjectContext:self.context];
    [fetchRequest setEntity:entity];
    NSSortDescriptor *sort = [[NSSortDescriptor alloc]
                              initWithKey:kDate ascending:NO];
    [fetchRequest setSortDescriptors:[NSArray arrayWithObject:sort]];

    NSPredicate *pred;

    if (self.willShowDebts) {
        pred = [NSPredicate predicateWithFormat:@"isDebt = YES"];  
    }else {
        pred = [NSPredicate predicateWithFormat:@"isLoan = YES"];
    }
    [fetchRequest setPredicate:pred];

    [self setFetchController:nil];
    self.fetchController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:self.context sectionNameKeyPath:nil cacheName:nil];

    NSError *error;
    if (![self.fetchController performFetch:&error]) {
        // Update to handle the error appropriately.
        NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
        exit(-1);  // Fail
    }
    [self.tableView reloadData];

    NSLog(@"fetch objects  %i",[[self.fetchController fetchedObjects] count]);

    [super viewWillAppear:animated];
}

私は自分のアプリでこれを約4回行います...そしてここでは完全には機能しません...最初はすべてのエンティティが表示されますが、戻って(ナビゲーションコントローラーにあります)、もう一度このビューに移動しますすべてがなくなった...何が

2012-09-06 13:54:15.994 app[1126:fe03] fetch objects  3
2012-09-06 13:54:19.254 app[1126:fe03] fetch objects  0
2012-09-06 13:54:22.145 app[1126:fe03] fetch objects  0
2012-09-06 13:54:24.328 app[1126:fe03] fetch objects  0

これはログ出力です...何かアイデアはありますか?

4

1 に答える 1

0

管理対象オブジェクトのコンテキストは毎回正しく設定されていますか (または正しく設定されていnilますか?)。

メソッドの最初の行にブレークポイントを置き、ステップスルーして、すべてが期待どおりであることを確認します。

于 2012-09-06T11:34:25.413 に答える