打开uiviewcontroller后出现NSObjectInaccessibleException

时间:2011-07-25 10:32:11

标签: ios uitableview core-data nsmanagedobject

我正在开发一个应用程序,其中自定义标签栏打开不同的tableview。 tableview的信息由JSON远程源提供。并使用自定义nsmanagedobject保存到Core Data中。

在didSelectRowAtIndexPath中打开和关闭uiview后触发错误。详细视图在桌面视图上打开,并在角落有一个关闭按钮。该视图仅适用于阅读文章,不适用于编辑,重写或删除。打开并关闭详细视图两次后出现错误。

日志表明NSManagedObject已失效。但是,当我没有删除或更新对象时,如何。它发生在每个细胞行。

我做错了什么?

日志:

  

*由于未捕获的异常'NSObjectInaccessibleException'而终止应用程序,原因是:'具有ID:0x75401c0的NSManagedObject已失效。'      
* *
第一次投掷筹码:   
(   
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   )   
终止调用抛出异常[切换到进程429线程0xec03]   
sharedlibrary apply-load-rules all   
当前语言:auto;目前的目标-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中发布的NSArrays。

3 个答案:

答案 0 :(得分:1)

您可能没有足够长时间保留对象(也就是自动释放)。所以当一段时间过去之后,你会尝试访问那些不存在的东西。尝试将数据传递给NSMutableArray,并将其用作“tableView:cellForRowAtIndexPath”上的数据源。

答案 1 :(得分:0)

核心数据中的NSObjectInaccessibleException表示您已获得对不在持久存储中的对象的引用。

通常,这意味着您已将其从上下文中删除,同时在其他位置保留对其的引用,例如对象属性或数组。

但是,如果您没有首先将对象正确添加到商店,也可能会收到错误。当您创建NSManagedObject实例而未将其正确插入有效上下文时,会发生这种情况。

在任何情况下,您的直接问题实际上在您创建和/或保存这些托管对象的代码中,而不是在tableview控制器代码中。这就是发生错误的地方,因为这是您尝试访问无效托管对象的地方。

答案 2 :(得分:0)

我是靠自己找到的。当我关闭覆盖的viewcontroller时,我必须重新加载tableview的数据。这不是任何数组或删除任何对象的问题。 喜欢

  

[myTable reloadData];