我有一个使用 NSFetchedResultsController 的 UITableViewController。如果我删除谓词,它可以正常工作,但是使用谓词,它会引发错误的访问(EXC_BAD_ACCESS)。我启用了 NSZombieEnabled,但没有任何结果。我正在使用ARC。我不明白!请帮忙。这是我的 fetchedresultscontroller 代码注意:将我的谓词更改为随机的简单谓词,例如“unitNumber = nil”或“unitNumber LIKE %@”,unString 仍然会导致崩溃,但是将谓词完全注释掉不会产生崩溃(但是我已经全部对象,显然没有过滤器):
- (NSFetchedResultsController *)fetchedResultsController
{
if (_fetchedResultsController != nil) {
return _fetchedResultsController;
}
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Unit" inManagedObjectContext:self.managedObjectContext];
[fetchRequest setEntity:entity];
// Predicate
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"workTicket.appointment.scheduleRowPointer = %@", rp];
[self.fetchedResultsController.fetchRequest setPredicate:predicate];
// Sort Descriptor
NSSortDescriptor *unitNumberDescriptor = [[NSSortDescriptor alloc] initWithKey:@"unitNumber" ascending:YES];
NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:unitNumberDescriptor, nil];
[fetchRequest setSortDescriptors:sortDescriptors];
_fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:self.managedObjectContext sectionNameKeyPath:@"addedToTicket" cacheName:nil];
return _fetchedResultsController;
}