简体   繁体   中英

Thread1: EXC_BAD_ACCESS(code=2, address=0x7fff5450df68)

I try to fetch data from coredata and display in tableview working with NSFetchResultController but show me error like this

Thread1: EXC_BAD_ACCESS(code=2, address=0x7fff5450df68) objective c

- (NSFetchedResultsController *)fetchResultController {

    AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
    _mainContext = [appDelegate manageObjectContext];

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

    NSFetchRequest *request = [[NSFetchRequest alloc] init];
    NSEntityDescription *entity = [NSEntityDescription entityForName:@"Student" inManagedObjectContext:_mainContext];
    [request setEntity:entity];
    //[request setFetchBatchSize:20];
    NSSortDescriptor *sort = [[NSSortDescriptor alloc] initWithKey:@"Student.name" ascending:NO];
    [request setSortDescriptors:[NSArray arrayWithObject:sort]];

    NSFetchedResultsController *theFetchResultController =[[NSFetchedResultsController alloc] initWithFetchRequest:request managedObjectContext:_mainContext sectionNameKeyPath:nil cacheName:@"Root"]; //this point show me error
    self.fetchResultController.delegate = theFetchResultController;

    return _fetchResultController;
}

Please help to fix this Problem.

This problem is occurs through this statement Edit this

 self.fetchResultController.delegate = theFetchResultController;

Replace with it.

self.fetchResultController.delegate = self

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM