我正在使用NSFetchedResultsController來填充UITableView,其結果來自1500個實體的中等大小Core Data存儲。結果控制器是相當標準的 - 對於這種設置,潛在錯誤的一些「熱點」不適用。來自NSFetchedResultsController的節名稱與被管對象值不匹配
-
上是相同的(主)線程創建爲
- 管理對象上下文其上
- 沒有高速緩存使用的,使用(因爲排序頻繁變化)
- 甲sectionNameKeyPath用於將結果分割成多個段
但是,我的部分結果很奇怪。例如,考慮這種方法用於設置標題段標題觀點:
- (NSString *)titleForHeaderInSection:(NSInteger)section {
id <NSFetchedResultsSectionInfo> sectionInfo = [[self.resultsController sections] objectAtIndex:section];
return [sectionInfo name]; // <------- Stopped at breakpoint here
}
我在指定的行使用斷點停止使用GDB,檢查以下內容:
(gdb) po [[self resultsController] sectionNameKeyPath]
reviewDateString
(gdb) print section
$11 = 1
(gdb) print (int) [sectionInfo numberOfObjects]
$12 = 4
(gdb) po [sectionInfo name]
Wednesday, September 8th 2010
(gdb) po [[[sectionInfo objects] objectAtIndex:0] valueForKey:@"reviewDateString"]
Sunday, February 13th 2011
(gdb) po [[[sectionInfo objects] objectAtIndex:1] valueForKey:@"reviewDateString"]
Sunday, February 13th 2011
(gdb) po [[[sectionInfo objects] objectAtIndex:2] valueForKey:@"reviewDateString"]
Sunday, February 13th 2011
(gdb) po [[[sectionInfo objects] objectAtIndex:3] valueForKey:@"reviewDateString"]
Sunday, February 13th 2011
這個問題應該是明顯的 - 爲什麼[sectionInfo name]沒有匹配節中每個被管理對象的sectionNameKeyPath的值?該部分中的對象看起來是正確分組的,部分名稱沒有正確設置。如果你看一下這個
的結果更奇:
(gdb) po [[self resultsController] indexPathForObject:(id)[[sectionInfo objects] objectAtIndex:0]]
<NSIndexPath 0x6615660> 2 indexes [459, 4294966310]
現在很明顯,從上面的NSIndexPath返回的應該是[1,0],這不假值。
我完全難住了。有人有主意嗎?如果您需要更多信息,我會看這個問題。
[編輯1]
我的NSFetchedResultsController設置中的一個奇怪的是,我重新創建(釋放和分配/初始化一個新的)響應一個UISegmentedControl的選擇變化的結果控制器。這是爲了更改提取請求和sectionNameKeyPath的sortDescriptors,以便整體排序發生更改。
[編輯2]
的resultsController方法僅僅是,我使用的NSFetchedResultsController,通過@synthesize生成的屬性訪問。
部分名稱的期望值已經給出 - 部分名稱應該等於我在「po [sectionInfo name]」下面顯示的@「reviewDateString」鍵(它是sectionNameKeyPath)的值,所以對於這種情況,他們應該是「2011年2月13日星期日」。
你可以發佈fetchResultController方法嗎? – shannoga 2011-02-16 06:38:15