【发布时间】:2011-07-25 10:32:11
【问题描述】:
我正在开发一个应用程序,其中有一个自定义标签栏打开不同的表格视图。表格视图的信息由 JSON 远程提要提供。并使用自定义 nsmanagedobject 保存到 Core Data 中。
我在 didSelectRowAtIndexPath 中打开和关闭 uiview 后触发错误。详细视图在 tableview 上方打开,并且在角落有一个关闭按钮。该视图仅用于阅读文章,不能用于编辑、重写或删除。在我打开和关闭详细视图两次后出现错误。
日志说 NSManagedObject 已失效。但是如何,当我不删除或更新对象时。它发生在每个单元格行中。
我做错了什么?
日志:
* 由于未捕获的异常“NSObjectInaccessibleException”而终止应用程序,原因:“ID:0x75401c0 的 NSManagedObject 已失效。”
* 首次抛出时调用堆栈:
(
0 CoreFoundation 0x013d15a9 异常预处理 + 185
1 libobjc.A.dylib 0x01525313 objc_exception_throw + 44
2 核心数据 0x0117f120 -[NSFaultHandler _fireFirstAndSecondLevelFaultsForObject:withContext:] + 0
3 核心数据 0x01110933 _PF_FulfillDeferredFault + 499
4 核心数据 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 layoutSubviews] + 242
11 QuartzCore 0x0014fa5a -[CALayer layoutSublayers] + 181
12 QuartzCore 0x00151ddc CALayerLayoutIfNeeded + 220
13 石英核心 0x000f70b4 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 310
14 石英核心 0x000f8294 _ZN2CA11Transaction6commitEv + 292
15 QuartzCore 0x000f846d _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 99
16 核心基础 0x013b289b __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION + 27
17 核心基础 0x013476e7 __CFRunLoopDoObservers + 295
18 核心基础 0x013101d7 __CFRunLoopRun + 1575
19 核心基础 0x0130f840 CFRunLoopRunSpecific + 208
20 核心基础 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]
sharedlibrary apply-load-rules all
当前语言:自动;目前客观-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。
【问题讨论】:
-
有什么理由不使用 NSFetchedResultsController 来管理 tableview 数据?这就是它的用途,尤其是对于带有部分的表格。
-
没有理由。它更稳定吗?
标签: ios uitableview core-data nsmanagedobject