打开 uiviewcontroller 后出现 NSObjectInaccessibleException
我正在开发一个应用程序,其中有一个自定义选项卡栏打开不同的表格视图。表视图的信息由 JSON 远程源提供。并使用自定义 nsmanagementobject 保存到 Core Data 中。
我在 didSelectRowAtIndexPath 中打开和关闭 uiview 后触发该错误。详细视图在表格视图上方打开,并在角落有一个关闭按钮。该视图仅供阅读文章,不可编辑、重写或删除。我打开和关闭详细视图两次后出现该错误。
日志显示 NSManagedObject 已失效。但是,当我不删除或更新对象时,如何实现。每个单元格行都会发生这种情况。
我做错了什么?
日志:
* 由于未捕获的异常“NSObjectInaccessibleException”而终止应用程序,原因:“ID 为 0x75401c0 的 NSManagedObject 已失效。”
* 第一次抛出时调用堆栈:
(
0 CoreFoundation 0x013d15a9 异常预处理 + 185
1 libobjc.A.dylib 0x01525313 objc_exception_throw + 44
2 CoreData 0x0117f120 -[NSFaultHandler _fireFirstAndSecondLevelFaultsForObject:withContext:] + 0
3 CoreData 0x01110933 _PF_FulfillDeferredFault + 499
4 CoreData 0x011149af _sharedIMPL_pvfk_core + 95
5 核心数据 0x011247c0 _pvfk_9 + 32
6 Ultima 0x00014bf7 -[ProgramTable tableView:cellForRowAtIndexPath:] + 4247
7 UIKit 0x004c1b98 -[UITableView(UITableViewInternal) _createPreparedCellForGlobalRow:withIndexPath:] + 634
8 UIKit 0x004b74cc -[UITableView(UITableViewInternal) _createPreparedCellForGlobalRow:] + 75
9 UIKit 0x004cc8cc -[UITableView(_UITableViewPrivate) _updateVisibleCellsNow:] + 1561
10 UIKit 0x004c490c -[UITableView 布局子视图] + 242
11 QuartzCore 0x0014fa5a -[CALayer 布局子层] + 181
12 QuartzCore 0x00151ddc CALayerLayoutIfNeeded + 220
13 QuartzCore 0x000f70b4 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 310
14 QuartzCore 0x000f8294 _ZN2CA11Transaction6commitEv + 292
15 QuartzCore 0x000f846d _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 99
16 CoreFoundation 0x013b289b __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION + 27
17 CoreFoundation 0x013476e7 __CFRunLoopDoObservers + 295
18 CoreFoundation 0x013101d7 __CFRunLoopRun + 1575
19 CoreFoundation 0x0130f840 CFRunLoopRunSpecific + 208
20 CoreFoundation 0x0130f761 CFRunLoopRunInMode + 97
21 图形服务 0x01e6d1c4 GSEventRunModal + 217
22 图形服务 0x01e6d289 GSEventRun + 115
23 UIKit 0x0045ac93 UIApplicationMain + 1160
24 Ultima 0x000028e9 主 + 121
25 Ultima 0x00002865 开始 + 53 )
终止调用抛出异常[切换到进程429线程0xec03]
共享库应用加载规则全部
当前语言:汽车;当前目标-c
我的 cellForRowAtIndexPath 看起来像:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
ProgramCelle *cell = (ProgramCelle*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[ProgramCelle alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
int row = indexPath.row;
int section = indexPath.section;
NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
[formatter setDateFormat:@"HH:mm"];
if(section == 0){
Program *p =[eight objectAtIndex:row];
cell.primaryTitle.text = p.title;
cell.primaryTitle.textColor = [UIColor blueColor];
Scene *s = p.scene;
cell.secondaryTitle.text = s.name;
NSDate *dato = p.tidspunkt;
NSString *time = [formatter stringFromDate:dato];
cell.klokke.text = time;
}
if(section == 1){
Program *p =[nine objectAtIndex:row];
cell.primaryTitle.text = p.title;
cell.primaryTitle.textColor = [UIColor blueColor];
Scene *s = p.scene;
cell.secondaryTitle.text = s.name;
NSDate *dato = p.tidspunkt;
NSString *time = [formatter stringFromDate:dato];
cell.klokke.text = time;
}
if(section == 2){
Program *p =[ten objectAtIndex:row];
cell.primaryTitle.text = p.title;
cell.primaryTitle.textColor = [UIColor blueColor];
Scene *s = p.scene;
cell.secondaryTitle.text = s.name;
NSDate *dato = p.tidspunkt;
NSString *time = [formatter stringFromDate:dato];
cell.klokke.text = time;
}
if(section == 3){
Program *p =[eleven objectAtIndex:row];
cell.primaryTitle.text = p.title;
cell.primaryTitle.textColor = [UIColor blueColor];
Scene *s = p.scene;
cell.secondaryTitle.text = s.name;
NSDate *dato = p.tidspunkt;
NSString *time = [formatter stringFromDate:dato];
cell.klokke.text = time;
}
if(section == 4){
Program *p =[twelve objectAtIndex:row];
cell.primaryTitle.text = p.title;
cell.primaryTitle.textColor = [UIColor blueColor];
Scene *s = p.scene;
cell.secondaryTitle.text = s.name;
NSDate *dato = p.tidspunkt;
NSString *time = [formatter stringFromDate:dato];
cell.klokke.text = time;
}
if(section == 5){
Program *p =[thirteen objectAtIndex:row];
cell.primaryTitle.text = p.title;
cell.primaryTitle.textColor = [UIColor blueColor];
Scene *s = p.scene;
cell.secondaryTitle.text = s.name;
NSDate *dato = p.tidspunkt;
NSString *time = [formatter stringFromDate:dato];
cell.klokke.text = time;
}
if(section == 6){
Program *p =[fourteen objectAtIndex:row];
cell.primaryTitle.text = p.title;
cell.primaryTitle.textColor = [UIColor blueColor];
Scene *s = p.scene;
cell.secondaryTitle.text = s.name;
NSDate *dato = p.tidspunkt;
NSString *time = [formatter stringFromDate:dato];
cell.klokke.text = time;
}
if(section == 7){
Program *p =[fifthteen objectAtIndex:row];
cell.primaryTitle.text = p.title;
cell.primaryTitle.textColor = [UIColor blueColor];
Scene *s = p.scene;
cell.secondaryTitle.text = s.name;
NSDate *dato = p.tidspunkt;
NSString *time = [formatter stringFromDate:dato];
cell.klokke.text = time;
}
if(section == 8){
Program *p =[sixteen objectAtIndex:row];
cell.primaryTitle.text = p.title;
cell.primaryTitle.textColor = [UIColor blueColor];
Scene *s = p.scene;
cell.secondaryTitle.text = s.name;
NSDate *dato = p.tidspunkt;
NSString *time = [formatter stringFromDate:dato];
cell.klokke.text = time;
}
if(section == 9){
Program *p =[seventeen objectAtIndex:row];
cell.primaryTitle.text = p.title;
cell.primaryTitle.textColor = [UIColor blueColor];
Scene *s = p.scene;
cell.secondaryTitle.text = s.name;
NSDate *dato = p.tidspunkt;
NSString *time = [formatter stringFromDate:dato];
cell.klokke.text = time;
}
[formatter release];
return cell;
}
其中八、九、十...是在 viewdidLoad 中启动并在 dealloc 中释放的 NSArray。
I am developing a app where with a custom tabbar opening different tableview. The information to the tableview is feeded by a JSON remote feed. And saved into Core Data with custom nsmanagedobject.
The error is triggered after I opening and closing uiview in didSelectRowAtIndexPath. The detail view is opening over the tableview and have a closing button in the corner. The view is only for read articles, not for edit, rewrite or delete. The error appear after I have opened and closed the detail view twice.
The log say that the NSManagedObject is has been invalidated. But how, when i am not deleting or updating the object. It happening with every cell row.
What i am doing wrong?
The log:
* Terminating app due to uncaught exception 'NSObjectInaccessibleException', reason: 'The NSManagedObject with ID:0x75401c0 has been invalidated.'
* Call stack at first throw:
(
0 CoreFoundation 0x013d15a9 exceptionPreprocess + 185
1 libobjc.A.dylib 0x01525313 objc_exception_throw + 44
2 CoreData 0x0117f120 -[NSFaultHandler _fireFirstAndSecondLevelFaultsForObject:withContext:] + 0
3 CoreData 0x01110933 _PF_FulfillDeferredFault + 499
4 CoreData 0x011149af _sharedIMPL_pvfk_core + 95
5 CoreData 0x011247c0 _pvfk_9 + 32
6 Ultima 0x00014bf7 -[ProgramTable tableView:cellForRowAtIndexPath:] + 4247
7 UIKit 0x004c1b98 -[UITableView(UITableViewInternal) _createPreparedCellForGlobalRow:withIndexPath:] + 634
8 UIKit 0x004b74cc -[UITableView(UITableViewInternal) _createPreparedCellForGlobalRow:] + 75
9 UIKit 0x004cc8cc -[UITableView(_UITableViewPrivate) _updateVisibleCellsNow:] + 1561
10 UIKit 0x004c490c -[UITableView layoutSubviews] + 242
11 QuartzCore 0x0014fa5a -[CALayer layoutSublayers] + 181
12 QuartzCore 0x00151ddc CALayerLayoutIfNeeded + 220
13 QuartzCore 0x000f70b4 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 310
14 QuartzCore 0x000f8294 _ZN2CA11Transaction6commitEv + 292
15 QuartzCore 0x000f846d _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 99
16 CoreFoundation 0x013b289b __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION + 27
17 CoreFoundation 0x013476e7 __CFRunLoopDoObservers + 295
18 CoreFoundation 0x013101d7 __CFRunLoopRun + 1575
19 CoreFoundation 0x0130f840 CFRunLoopRunSpecific + 208
20 CoreFoundation 0x0130f761 CFRunLoopRunInMode + 97
21 GraphicsServices 0x01e6d1c4 GSEventRunModal + 217
22 GraphicsServices 0x01e6d289 GSEventRun + 115
23 UIKit 0x0045ac93 UIApplicationMain + 1160
24 Ultima 0x000028e9 main + 121
25 Ultima 0x00002865 start + 53
)
terminate called throwing an exception[Switching to process 429 thread 0xec03]
sharedlibrary apply-load-rules all
Current language: auto; currently objective-c
My cellForRowAtIndexPath looks like:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
ProgramCelle *cell = (ProgramCelle*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[ProgramCelle alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
int row = indexPath.row;
int section = indexPath.section;
NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
[formatter setDateFormat:@"HH:mm"];
if(section == 0){
Program *p =[eight objectAtIndex:row];
cell.primaryTitle.text = p.title;
cell.primaryTitle.textColor = [UIColor blueColor];
Scene *s = p.scene;
cell.secondaryTitle.text = s.name;
NSDate *dato = p.tidspunkt;
NSString *time = [formatter stringFromDate:dato];
cell.klokke.text = time;
}
if(section == 1){
Program *p =[nine objectAtIndex:row];
cell.primaryTitle.text = p.title;
cell.primaryTitle.textColor = [UIColor blueColor];
Scene *s = p.scene;
cell.secondaryTitle.text = s.name;
NSDate *dato = p.tidspunkt;
NSString *time = [formatter stringFromDate:dato];
cell.klokke.text = time;
}
if(section == 2){
Program *p =[ten objectAtIndex:row];
cell.primaryTitle.text = p.title;
cell.primaryTitle.textColor = [UIColor blueColor];
Scene *s = p.scene;
cell.secondaryTitle.text = s.name;
NSDate *dato = p.tidspunkt;
NSString *time = [formatter stringFromDate:dato];
cell.klokke.text = time;
}
if(section == 3){
Program *p =[eleven objectAtIndex:row];
cell.primaryTitle.text = p.title;
cell.primaryTitle.textColor = [UIColor blueColor];
Scene *s = p.scene;
cell.secondaryTitle.text = s.name;
NSDate *dato = p.tidspunkt;
NSString *time = [formatter stringFromDate:dato];
cell.klokke.text = time;
}
if(section == 4){
Program *p =[twelve objectAtIndex:row];
cell.primaryTitle.text = p.title;
cell.primaryTitle.textColor = [UIColor blueColor];
Scene *s = p.scene;
cell.secondaryTitle.text = s.name;
NSDate *dato = p.tidspunkt;
NSString *time = [formatter stringFromDate:dato];
cell.klokke.text = time;
}
if(section == 5){
Program *p =[thirteen objectAtIndex:row];
cell.primaryTitle.text = p.title;
cell.primaryTitle.textColor = [UIColor blueColor];
Scene *s = p.scene;
cell.secondaryTitle.text = s.name;
NSDate *dato = p.tidspunkt;
NSString *time = [formatter stringFromDate:dato];
cell.klokke.text = time;
}
if(section == 6){
Program *p =[fourteen objectAtIndex:row];
cell.primaryTitle.text = p.title;
cell.primaryTitle.textColor = [UIColor blueColor];
Scene *s = p.scene;
cell.secondaryTitle.text = s.name;
NSDate *dato = p.tidspunkt;
NSString *time = [formatter stringFromDate:dato];
cell.klokke.text = time;
}
if(section == 7){
Program *p =[fifthteen objectAtIndex:row];
cell.primaryTitle.text = p.title;
cell.primaryTitle.textColor = [UIColor blueColor];
Scene *s = p.scene;
cell.secondaryTitle.text = s.name;
NSDate *dato = p.tidspunkt;
NSString *time = [formatter stringFromDate:dato];
cell.klokke.text = time;
}
if(section == 8){
Program *p =[sixteen objectAtIndex:row];
cell.primaryTitle.text = p.title;
cell.primaryTitle.textColor = [UIColor blueColor];
Scene *s = p.scene;
cell.secondaryTitle.text = s.name;
NSDate *dato = p.tidspunkt;
NSString *time = [formatter stringFromDate:dato];
cell.klokke.text = time;
}
if(section == 9){
Program *p =[seventeen objectAtIndex:row];
cell.primaryTitle.text = p.title;
cell.primaryTitle.textColor = [UIColor blueColor];
Scene *s = p.scene;
cell.secondaryTitle.text = s.name;
NSDate *dato = p.tidspunkt;
NSString *time = [formatter stringFromDate:dato];
cell.klokke.text = time;
}
[formatter release];
return cell;
}
Where eight, nine, ten ... are NSArrays that is initiated in viewdidLoad and released in dealloc.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可能没有保留对象足够长的时间(也称为自动释放)。因此,当一段时间过去后,您会尝试访问不再存在的东西。尝试将数据传递到 NSMutableArray 并将其用作“tableView:cellForRowAtIndexPath”上的数据源。
You probably are not retaining the objects long enough (aka autorelease). So when some time passes, you try to access something that there is not there anymore. Try passing your data to an NSMutableArray and use it as your datasource on your "tableView:cellForRowAtIndexPath".
Core Data 中的 NSObjectInaccessibleException 意味着您获得了对不在持久存储中的对象的引用。
通常,这意味着您已从上下文中删除它,同时在其他地方(例如对象属性或数组)保留对它的引用。
但是,如果您一开始没有正确地将对象添加到存储中,您也可能会收到错误消息。当您创建 NSManagedObject 实例而没有将其正确插入到有效上下文中时,就会发生这种情况。
在任何情况下,您的直接问题实际上是在您创建和/或保存这些托管对象的代码中,而不是在表视图控制器代码中。这就是错误发生的地方,因为这是您尝试访问无效的托管对象的地方。
The
NSObjectInaccessibleException
in Core Data means that you've got a reference to an object that is not in the persistent store.Usually, this means that you've deleted it from the context while maintaining a reference to it elsewhere e.g. an object property or an array.
However, you can also get the error if you don't properly add an object to a store in the first place. This happens when you create a NSManagedObject instance without properly inserting it in a valid context.
In any, case, your immediate problem is actually in the code where you create and/or save these managed objects and not in the tableview controller code. That is simply where the error occurs because that is where you try to access the invalid managed objects.
我自己发现的。当我关闭覆盖视图控制器时,我必须重新加载表视图的数据。这不是任何数组或删除任何对象的问题。
喜欢
I found it out by my self. When I am closing the overlaying viewcontroller, I have to reload the data of the tableview. It was not a problem of any array or deleting any object.
Like