NSFetchResultsController (frc) が入った UITableViewController (TVC) があります。frc の初期化は次のとおりです。
- (NSFetchedResultsController *)frc
{
if (!_frc)
{
NSFetchRequest *request = [[NSFetchRequest alloc] initWithEntityName:e_product];
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"product_group.product_group_name" ascending:YES];
request.sortDescriptors = [NSArray arrayWithObject:sortDescriptor];
_frc = [[NSFetchedResultsController alloc] initWithFetchRequest:request managedObjectContext:self.moc sectionNameKeyPath:@"product_group.product_group_name" cacheName:nil];
_frc.delegate = self;
NSError *error;
if (![_frc performFetch:&error])
{
NSLog(@"Error: %@!", error.userInfo);
}
if (_frc.sections.count < 1)
{
// looks like the product list is empty!
[self refreshProductCatalog];
}
}
return _frc;
}
TVC が表示されると、frc は初めてフェッチを実行し、「製品」エンティティがないことを確認して、refreshProductCatalog でそれらを要求します。新しいエンティティが追加された後、frc はそれを「感じ」、TVC アイテムを適切にリロードします (TVC の場合、self はデリゲートです)。
FetchRequest に述語を追加すると、問題が発生します。
request.predicate = [NSPredicate predicateWithFormat:@"SELF IN %@", someManagedObject.setOfProductsEntities];
refreshProductCatalog の someManagedObject.setOfProductsEntities に適切なエンティティを入力します (再起動後に正常に動作するためと確信しています)。問題は、述語が配置されている場合、データを変更した後、frc が管理対象オブジェクト コンテキストの変更を「認識」せず、TVC をリロードしないことです。TVC を離れてもう一度開く (またはアプリを再起動する) と、すべて問題なく、データは既に保存されています...
ここで何が問題なのか手がかりはありますか? ありがとうございました ;)