我有一个使用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;
}
答案 0 :(得分:1)
变化:
[self.fetchedResultsController.fetchRequest setPredicate:predicate];
到:
[fetchRequest setPredicate:predicate];