1

我認爲這會工作,但我不知道爲什麼我做錯了。我使用的謂詞在下面的代碼已取得的成果控制器:NSFetchedResultsController委託方法不爲這些更改觸發

NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; 
NSEntityDescription * entity = [NSEntityDescription entityForName:@"SearchResult" inManagedObjectContext:[[DataInterfaceObject sharedAlloc] managedObjectContext]];  
[fetchRequest setEntity:entity];  
[fetchRequest setFetchBatchSize:10]; 

// Results Table predicate 
NSPredicate *predicate_Results = [NSCompoundPredicate andPredicateWithSubpredicates:[NSArray arrayWithObjects: [ResultsTableVC resultsPredicate], [NSPredicate predicateWithFormat:@"searchUsed.isCollapsedView == NO"], nil]]; 

// Favorites Table predicate 
NSPredicate *predicate_Favorites = [NSCompoundPredicate andPredicateWithSubpredicates:[NSArray arrayWithObjects: [FavoritesTableVC favoritesPredicate], [NSPredicate predicateWithFormat:@"favoritesInfoLink.isCollapsedView == NO"], nil]]; 

// Full predicate 
NSPredicate *predicate = 
[NSCompoundPredicate orPredicateWithSubpredicates: [NSArray arrayWithObjects: 
                predicate_Results, predicate_Favorites, nil]]; 

[NSFetchedResultsController deleteCacheWithName:@"resultsCache"]; 
[fetchRequest setPredicate:predicate]; 

的目的是獲取匹配謂詞所有SearchResult實體。 SearchResult實體具有如下的searchUsed關係:SearchResult < < - > SearchTerms。 SearchTerms有一個屬性isCollapsedView

用戶可以點擊一個視圖並導致相應的對象視圖摺疊,並且此時searchUsed.isCollapsedView的值被更新並保存到moc中。我已經證實,這是發生。

我希望這個改變能被提取的結果控制器識別,然後委託方法會觸發,但它們不會。

委託方法在插入,刪除或更新搜索實體時觸發。

我是否有這個設置錯誤,或者我的期望錯誤?我能做些什麼呢?

回答

1

我發現只需觸摸entity任務中提到的實體類型的屬性就足夠了。然後該實體被moc識別爲更改/更新。顯然,在這一點上,frc會將謂詞(包括關係)應用於這些更改的實體,以確定是否存在插入,刪除或更新。 (通過觸摸,我的意思是隻分配一個與現有值相同的值,然後將其保存到mod中。)這樣做可以避免添加已在關係實體中捕獲的屬性。

+0

是的,這將遵循我描述的行爲。有點可笑,但我想這是你可以採取的一種方法。 – gschandler 2012-07-23 05:27:57

2

你的期望是錯誤的。它只會觸發對SearchResult實體的屬性或關係的更改,而不會觸發屬性的更改關係

如果您要對數據進行非規範化處理,並將摺疊狀態布爾值(或使用位域等)拉入您的SearchResult模型中,您將獲得委託調用的好處。

相關問題