首页 文章

打开uiviewcontroller后出现NSObjectInaccessibleException

提问于
浏览
0

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

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

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

我做错了什么?

日志:

*由于未捕获的异常'NSObjectInaccessibleException'而终止应用程序,原因是:'具有ID:0x75401c0的NSManagedObject已失效 . ' [:withContext:NSFaultHandler _fireFirstAndSecondLevelFaultsForObject] 0 3 CoreData 0x01110933 _PF_FulfillDeferredFault 499 4 CoreData 0x011149af _sharedIMPL_pvfk_core 95 5 CoreData 0x011247c0 _pvfk_9 32 6 - (0的CoreFoundation 0x013d15a9 exceptionPreprocess 185 1 libobjc.A.dylib 0x01525313 objc_exception_throw 44 2 CoreData 0x0117f120:*在第一掷调用堆栈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 QuartzCo重新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主121 25 Ultima 0x00002865启动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

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

  • 1

    核心数据中的 NSObjectInaccessibleException 意味着您已获得对不在持久存储中的对象的引用 .

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

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

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

  • 0

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

    [myTable reloadData];

相关问题