我有这样的工作代码,但现在我需要能够基于在predicateWithFormat使用的对象,就可以改变NSPredicate,如下所示:NSPredicate predicateWithFormat与对象随时间变化
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription
entityForName:@"Item" inManagedObjectContext:_context];
[fetchRequest setPredicate:[NSPredicate predicateWithFormat:@"self.atrObj == %@", _currentUser.atrObj.objectID]];
[fetchRequest setEntity:entity];
NSSortDescriptor *sortContent = [[NSSortDescriptor alloc] initWithKey:@"date" ascending:NO];
[fetchRequest setSortDescriptors:[NSArray arrayWithObject:sortContent]];
[fetchRequest setFetchBatchSize:10];
NSFetchedResultsController *theFetchedResultsController =
[[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest
managedObjectContext:_context sectionNameKeyPath:nil
cacheName:nil];
self.fetchedResultsController = theFetchedResultsController;
self.fetchedResultsController.delegate = self;
我需要的当我更改具有此tableviewcontroller属性的应用程序委托中的_currentUser对象时,fetchedResultsControlelr将使用新的_currentUser对象。
[self.tableViewcontroller setCurrentUser:user];
谢谢!
谢谢!我不知道你可以随时改变谓词,知道的好东西! – 2012-03-29 02:45:27