奇怪的错误:在NSFetchedResultsController中取消注释NSPredicate将清空UITableView

时间:2013-10-22 22:27:42

标签: ios uitableview nspredicate nsfetchedresultscontroller

我有一个奇怪的错误:如果我取消注释NSPredicate,则生成的UITableView为空。

我的数据模型如下:         类别< - >> Feed< - >>交

我正在抓取PostPost.feedPost的{​​{1}}。 Feed具有Feed rss属性。

以下是代码:

NString

如果我取消注释 - (NSFetchedResultsController *)fetchedResultsController { // Set up the fetched results controller if needed. if (_fetchedResultsController == nil) { // Create the fetch request for the entity. NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; // Edit the entity name as appropriate. NSEntityDescription *entity = [NSEntityDescription entityForName:@"Post" inManagedObjectContext:_globalMOC]; [fetchRequest setEntity:entity]; // Edit the sort key as appropriate. NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"date" ascending:NO]; NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil]; [fetchRequest setSortDescriptors:sortDescriptors]; NSPredicate *predicate =[NSPredicate predicateWithFormat:@"feed.rss == %@", _detailItem.rss]; [fetchRequest setPredicate:predicate]; // Edit the section name key path and cache name if appropriate. // nil for section name key path means "no sections". NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:_globalMOC sectionNameKeyPath:nil cacheName:nil]; self.fetchedResultsController = aFetchedResultsController; self.fetchedResultsController.delegate = self; NSError *error = nil; if (![self.fetchedResultsController performFetch:&error]) { // Replace this implementation with code to handle the error appropriately. // abort() causes the application to generate a crash log and terminate. // You should not use this function in a shipping application, although it may be useful // during development. If it is not possible to recover from the error, display an alert // panel that instructs the user to quit the application by pressing the Home button. // NSLog(@"Unresolved error %@, %@", error, [error userInfo]); abort(); } } return _fetchedResultsController; } ,我只会看到结果。我尝试使用NSPredicateLIKE==,在=周围加上双引号和单引号...

最好是直接比较%@对象......

任何人都可以帮助我?

1 个答案:

答案 0 :(得分:0)

解决here

问题是NSFetchedResultsController_detailItem被设置之前初始化了一次。