我正在開發一個使用CoreData的應用程序。該視圖包含一個使用NSFetchedResultsController的UITableView(包含大約50個元素)。還有一個「Pull to refresh」,允許在WS調用之後刷新存儲的數據(在具有新的託管對象上下文的另一個線程中)。iOS4上的NSFetchedResultsController問題
一切工作正常在iOS5上:當我執行「拉刷新」時刷新數據庫和tableview。但是,iOS4存在問題。當應用程序啓動(在tableview中包含了所有的數據庫記錄),但我有以下錯誤,當我進行「拉刷新」第一次「performFetch」作品:
2012-02-29 11:56:09.119 Nanopost[1996:207] *** Terminating app due to uncaught exception 'NSObjectInaccessibleException', reason: 'CoreData could not fulfill a fault for '0x5c3c760 <x-coredata://E176B0A1-275B-4332-9231-49FD88238C2B/Ads/p231>''
*** Call stack at first throw:
(
0 CoreFoundation 0x02bfe919 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x02e595de objc_exception_throw + 47
2 CoreData 0x028b833f _PFFaultHandlerLookupRow + 1407
3 CoreData 0x028b5ee3 _PF_FulfillDeferredFault + 499
4 CoreData 0x028b9f3f _sharedIMPL_pvfk_core + 95
5 CoreData 0x0292a010 _PF_Handler_Public_GetProperty + 160
6 Foundation 0x02442c4f -[NSSortDescriptor compareObject:toObject:] + 128
7 CoreData 0x0297db5e +[NSFetchedResultsController(PrivateMethods) _insertIndexForObject:inArray:lowIdx:highIdx:sortDescriptors:] + 286
8 CoreData 0x0297e1b2 -[NSFetchedResultsController(PrivateMethods) _postprocessInsertedObjects:] + 402
9 CoreData 0x029841bc -[NSFetchedResultsController(PrivateMethods) _managedObjectContextDidChange:] + 1804
10 Foundation 0x02380c1d _nsnote_callback + 145
11 CoreFoundation 0x02bd6cf9 __CFXNotificationPost_old + 745
12 CoreFoundation 0x02b5611a _CFXNotificationPostNotification + 186
13 Foundation 0x023767c2 -[NSNotificationCenter postNotificationName:object:userInfo:] + 134
14 CoreData 0x028c0519 -[NSManagedObjectContext(_NSInternalNotificationHandling) _postObjectsDidChangeNotificationWithUserInfo:] + 89
15 CoreData 0x028f802b -[NSManagedObjectContext mergeChangesFromContextDidSaveNotification:] + 1579
16 Foundation 0x02395e9a __NSThreadPerformPerform + 251
17 CoreFoundation 0x02bdfd7f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
18 CoreFoundation 0x02b3e2cb __CFRunLoopDoSources0 + 571
19 CoreFoundation 0x02b3d7c6 __CFRunLoopRun + 470
20 CoreFoundation 0x02b3d280 CFRunLoopRunSpecific + 208
21 CoreFoundation 0x02b3d1a1 CFRunLoopRunInMode + 97
22 GraphicsServices 0x031e62c8 GSEventRunModal + 217
23 GraphicsServices 0x031e638d GSEventRun + 115
24 UIKit 0x0063cb58 UIApplicationMain + 1160
25 Nanopost 0x0000230a main + 170
26 Nanopost 0x00002255 start + 53
)
terminate called after throwing an instance of '_NSCoreDataException'
當我初始化「NSFetchRequest 」我的設置 「FetchBatchSize」 20(隨機):
[l_FetchRequest setFetchBatchSize:20];
但如果我設置了 「FetchBatchSize」,以25:
[l_FetchRequest setFetchBatchSize:25];
...沒有更多的崩潰對iOS4的和我不「T知道爲什麼,我想了解這個問題:)我不認爲這條線是真正的問題。也許它表明另一個問題呢?
非常感謝您提前回答您的問題!
Thomas
喜達,感謝您的回答! 我使用不同的上下文,因爲它似乎是根據Apple的文檔(另一個線程=另一個託管對象上下文)的「最佳實踐」。 我試圖添加一個「異常斷點」。不幸的是,在main.m文件中引發了異常,所以要解決這個問題並不容易。 Thomas – 2012-03-01 08:20:03
main.m中的異常意味着它沒有被處理並展開整個堆棧。你的異常斷點在拋出時會立即升起 - 再試一次,直到它正常工作,關鍵是看看程序何時中斷。 – 2012-03-01 16:43:48