我正在开发一个使用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