执行获取请求时,核心数据应用程序崩溃

时间:2011-10-21 08:26:19

标签: iphone

我从核心数据实体获取结果

- (NSFetchedResultsController *)fetchedResultsController {

    if (fetchedResultsController != nil) {
        return fetchedResultsController;
    }

    // Set up the fetched results controller.

    // Create the fetch request for the entity.
    NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
    // Edit the entity name as appropriate.
    NSEntityDescription *entity = [NSEntityDescription entityForName:@"Tutorial" inManagedObjectContext:managedObjectContext];
    [fetchRequest setEntity:entity];

    // Set the batch size to a suitable number.
    [fetchRequest setFetchBatchSize:20];

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


    //sorting 
    [fetchRequest setSortDescriptors:sortDescriptors];

    NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:managedObjectContext sectionNameKeyPath:nil cacheName:@"Root"];
    aFetchedResultsController.delegate = self;
    self.fetchedResultsController = aFetchedResultsController;

    //release here
    [aFetchedResultsController release];
    [fetchRequest release];
    [sortDescriptor release];
    [sortDescriptors release];

    return fetchedResultsController;
}

我的应用在执行提取时崩溃

- (void)viewDidLoad
{
    [super viewDidLoad];

    //title


    self.navigationItem.leftBarButtonItem = self.editButtonItem;
    //add song button



    UIBarButtonItem *addSongbutton = [[UIBarButtonItem alloc] initWithTitle:@"Add Songs" style:UIBarButtonItemStyleBordered target:self action:@selector(addSongs)];
    self.navigationItem.rightBarButtonItem = addSongbutton;

    [addSongbutton release];

    if (managedObjectContext == nil) {
        managedObjectContext = [(SongsWithLyricsAppDelegate *)[[UIApplication sharedApplication]delegate]managedObjectContext];
    }

    self.title = @"Song List";

    //Error message
    NSError *error =nil;
    if (![[self fetchedResultController]performFetch:&error]) {
        NSLog(@"Unresolved error %@, %@", error, [error userInfo]);

        abort();

    }




}

这是Nslog输出 未解决的错误(null),(null)
请帮忙

2 个答案:

答案 0 :(得分:0)

grrr ...总是在注释中推送返回...我想补充一点,(null)(null)的错误输出看起来好像没有错误,但是fetch不应该返回false

当你尝试调用performFetch时,你确定fetchedResultsController不是nil吗?

答案 1 :(得分:0)

您的setFetchedResultsController实施是否有错误?