Debugging 核心数据丢失实体
我不明白这里发生了什么Debugging 核心数据丢失实体,debugging,ios5,core-data,Debugging,Ios5,Core Data,我不明白这里发生了什么 -(void)viewWillAppear:(BOOL)animated { NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; NSEntityDescription *entity = [ NSEntityDescription entityForName:kTransaction inManagedObjectContext:self.context]; [fet
-(void)viewWillAppear:(BOOL)animated
{
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [ NSEntityDescription entityForName:kTransaction inManagedObjectContext:self.context];
[fetchRequest setEntity:entity];
NSSortDescriptor *sort = [[NSSortDescriptor alloc]
initWithKey:kDate ascending:NO];
[fetchRequest setSortDescriptors:[NSArray arrayWithObject:sort]];
NSPredicate *pred;
if (self.willShowDebts) {
pred = [NSPredicate predicateWithFormat:@"isDebt = YES"];
}else {
pred = [NSPredicate predicateWithFormat:@"isLoan = YES"];
}
[fetchRequest setPredicate:pred];
[self setFetchController:nil];
self.fetchController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:self.context sectionNameKeyPath:nil cacheName:nil];
NSError *error;
if (![self.fetchController performFetch:&error]) {
// Update to handle the error appropriately.
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
exit(-1); // Fail
}
[self.tableView reloadData];
NSLog(@"fetch objects %i",[[self.fetchController fetchedObjects] count]);
[super viewWillAppear:animated];
}
我在我的应用程序中这样做了大约4次。。。在这里,它不太起作用。。。第一次它显示所有实体,但如果我返回(它在导航控制器中),然后再次转到此视图,所有内容都将消失。。。给什么
2012-09-06 13:54:15.994 app[1126:fe03] fetch objects 3
2012-09-06 13:54:19.254 app[1126:fe03] fetch objects 0
2012-09-06 13:54:22.145 app[1126:fe03] fetch objects 0
2012-09-06 13:54:24.328 app[1126:fe03] fetch objects 0
这是日志输出。。。
有什么想法吗?您的托管对象上下文是否每次都设置正确(或者是
nil
)
在方法的第一行设置一个断点并逐步执行,检查所有内容是否如您所期望的那样。创建结果时使用的唯一明显的方法是
self.context
和self.willshowdebnts
(假设您没有明确删除任何内容)。将这两种方法都记录下来,看看它们在调用之间是否发生了变化,这会很有趣。。。这不是零。self.willShowDebt是指定的布尔财产。。。我不认为设置错误,但会再次检查Self.willShowDebts设置不正确……绝对不是零…:(