Note: This question has been completely re-organized due to so many down votes.

I am displaying a UITableViewController using NSFetchedResults with core data. It displays fine, but when I push a new view controller and the user uses the back button to navigate back to the UITableView its crashes with that error.

I have been battling this for weeks and have not figured out why. I can tell that its likely related to memory management but I cant find it anywhere.

Update: Using Instruments-Zombies I found out that in fact it was crashing on CoreData -prepareResultsForResultsSet. See image enter image description here Here is the code from my FetchedResultsController

- (NSFetchedResultsController *)fetchedResultsController {

NSManagedObjectContext *thecontext;
thecontext = [(Logix_AppDelegate *)[[UIApplication sharedApplication] delegate] managedObjectContext];

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

NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"TimeOff" inManagedObjectContext:thecontext];
[fetchRequest setEntity:entity];
NSSortDescriptor *sort = [[NSSortDescriptor alloc] initWithKey:@"timeOffStartDate" ascending:NO];
[fetchRequest setSortDescriptors:[NSArray arrayWithObject:sort]];
[fetchRequest setFetchBatchSize:20];
NSFetchedResultsController *theFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:thecontext sectionNameKeyPath: @"timeOffType" cacheName:nil];
self.fetchedResultsController = theFetchedResultsController;
fetchedResultsController.delegate = self;
[sort release];
[fetchRequest release];
[theFetchedResultsController release];
return fetchedResultsController;    
}
有帮助吗?

解决方案

Can you copy/paste the actual error from Xcode? And backtrace of where the crash happens, if any?

You definitely should not be autoreleaseing the object returned by +imageNamed:; that object is already autoreleased.


Your comment:

iVacationTimeApp[47892:19d03] -[CFString respondsToSelector:]: message sent to deallocated instance 0x95c9140

There is your answer. You have an overreleased object. May be the image, might be something else. Turn on Zombie detection in Instruments and run again.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top