开发者

Calling ViewController returns nil

开发者 https://www.devze.com 2022-12-28 20:21 出处:网络
I am trying to resolve this for days at this stage and I\'m hoping you can help. I have two ViewControllers which query two different tables from the same database using Core Data. The first ViewCont

I am trying to resolve this for days at this stage and I'm hoping you can help.

I have two ViewControllers which query two different tables from the same database using Core Data. The first ViewController is opened with the app and displays fine. The second is called from within the first ViewController, using a pretty standard fetch setup:

- (NSFetchedResultsController *)fetchedClients {
    // Set up the fetched results controller if needed.
    if (fetchedClients == nil) {
        // Create the fetch request for the entity.
        NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
        // Edit the entity name as appropriate.
        NSEntityDescription *entity = [NSEntityDescription entityForName:@"Clients" 
              inManagedObjectContext:managedObjectContext];
        [fetchRequest setEntity:entity];




        // Edit the sort key as appropriate.
        NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"clientsName" ascending:YES];
        NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil];

        [fetchRequest setSortDescriptors:sortDescriptors];

        // Edit the section name key path and cache name if appropriate.
        // nil for section name key path means "no sections".
        NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] 
                 initWithFetchRequest:fetchRequest
               开发者_JAVA技巧  managedObjectContext:managedObjectContext
                 sectionNameKeyPath:nil
                 cacheName:@"Root"];
        aFetchedResultsController.delegate = self;
        self.fetchedClients = aFetchedResultsController;

        [aFetchedResultsController release];
        [fetchRequest release];
        [sortDescriptor release];
        [sortDescriptors release];
    }

 return fetchedClients;
}    

When I call [self.fetchedClients sections], I get a nil (0x0) return.

I have examined the database using an external application to ensure data exists in the "Clients" table.


Are you compiling against 3.0? Thee is a bug in 3.0 that was fixed in 3.1 that can cause this issue.

update

Are you calling -performFetch: on the returned NSFetchedResultsController? I dont't see it in the code you posted.

0

精彩评论

暂无评论...
验证码 换一张
取 消