【发布时间】:2013-12-09 23:29:26
【问题描述】:
当我在我的表视图控制器中调用 fetchQuery 方法时,它返回了一个具有空属性的对象,但我还没有保存任何东西。事实上,我刚刚清理了我的 xcode 缓存和 IOS 模拟器。这是我的 fetchQuery 方法:
在我看来DidLoad
NSMutableArray *people = [[NSMutableArray alloc] init];
在我看来WillAppear
NSManagedObjectContext *context = [self managedObjectContext];
NSFetchRequest *request = [[NSFetchRequest alloc] initWithEntityName:@"Person"];
self.people = [[context executeFetchRequest:request error:nil] mutableCopy];
[self.table reloadData];
cellForRowAtIndexPath
Person *temp = ((Person*)[people objectAtIndex:indexPath.row]);
PersonCell *cell = [tableView dequeueReusableCellWithIdentifier:@"personCell"];
if (cell == nil) {
cell = [[PersonCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"personCell"];
}
[cell setPersonDetails:temp]; // just assigning label value, had double checked, it works.
return cell;
这种奇怪的行为破坏了 numberOfRowsInSection 计数,导致 cellForRowAtIndexPath 中出现以下异常:
Thread 1: EXC_BAD_ACCESS(code=1, address=0x10)
有人知道怎么回事吗?
截图说明:
- 日期:出生日期
- 数字:行数
- 日期和数字之间的空白区域:应该是 NSString firstName
【问题讨论】:
-
你能发布控制台日志的输出吗?
-
people 数组可变有什么原因吗?
-
你能多放点 sn-p 吗?
-
试试这样 NSManagedObject *newDevice = [NSEntityDescription insertNewObjectForEntityForName:@"Person" inManagedObjectContext:context]; NSLog(@"%@",[NSString stringWithFormat:@"%@ %@", [newDevice valueForKey:@"MyattributeName1"], [newDevice valueForKey:@"MyattributeName2"]]])
-
@FelixLam:原因是因为用户可以将人员添加到人员上,我调用了 [self.table reload] 方法来重新加载表格单元格。
标签: ios core-data xcode5 nsfetchrequest