objective-c - 从 NSFetchedResultsController 检测 sectionNameKeyPath 的更新

标签 objective-c ios core-data updates

情况是这样的。我有 2 个模型:

  • 运动(具有属性名称和关系玩家)
  • 播放器(具有属性名称和 relationShip sport)

在 ViewController 中,我不想在按运动排序的 UITableView 中显示所有玩家。 当玩家名称更改时,将调用 NSFetchedResultsControllerDelegate 回调。

但是当 Sport 的名称更新时,不会调用 NSFetchedResultsControllerDelegate 回调。

这是正常行为吗?我如何知道 Sport.name 的更新(无需创建另一个 NSFetchedResultsController)?

谢谢你和最好的问候。

NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"sport.name != NULL"];
[fetchRequest setPredicate:predicate];


NSArray *sortDescriptors = [NSArray arrayWithObjects:
                              [NSSortDescriptor sortDescriptorWithKey:@"sport.name" ascending:YES], 
                              [NSSortDescriptor sortDescriptorWithKey:@"name" ascending:YES],
                              nil];
[fetchRequest setSortDescriptors:sortDescriptors];


NSEntityDescription *entityDescription = [NSEntityDescription entityForName:@"Player" 
                                         inManagedObjectContext:self.managedObjectContext];
[fetchRequest setEntity:entityDescription];


fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest 
                                          managedObjectContext:self.managedObjectContext 
                                         sectionNameKeyPath:@"sport.name" 
                                               cacheName:nil];
[fetchRequest release];

fetchedResultsController.delegate = self;


NSError *error = nil;
if ([fetchedResultsController performFetch:&error] == NO) {
     ALog(@"Fetch error: %@", [error localizedDescription]);
}

最佳答案

你可以使用提示:

 If (fetchresultcontroller != nil || isOtherEnthityUpdate)
 {
      return fetchresultcontroller;
 }

并从您检查其他实体的任何地方重新加载 self.tableview。它可以是通知中心或其他tableview。

关于objective-c - 从 NSFetchedResultsController 检测 sectionNameKeyPath 的更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5322619/

相关文章:

ios - 从 WAV 文件中读取原始音频样本

ios - NSManagedObjectContext.performBlockAndWait() 在主线程/队列上运行 block

ios - UIWebImage+ AFNetworking 图像在单元格中移动

ios - 使用 arc4random 的更好方法

android - 如何让 SNS 在 Android 中工作?

ios - 核心数据按自增索引排序?

iOs 设置原始值

ios - 使用 Apptentive : -[ATAppRatingFlow appDidLaunch:viewController:] 时无法识别的选择器

ios - 使用NSInteger作为NSDictionary objectForKey中的类型ID

ios - Swift:解码任意协议(protocol)类型