Iphone 核心数据错误“;提取请求必须有一个实体“QUOTE”;
我尝试将TopSongs解析器和核心数据文件添加到我的应用程序中,现在它构建成功,没有错误或警告消息。但是,应用程序一旦加载,就会崩溃,原因如下: 更新:我已经完成了所有工作,但是我的TableView没有显示任何数据,应用程序也没有响应以下断点Iphone 核心数据错误“;提取请求必须有一个实体“QUOTE”;,iphone,parsing,uitableview,core-data,Iphone,Parsing,Uitableview,Core Data,我尝试将TopSongs解析器和核心数据文件添加到我的应用程序中,现在它构建成功,没有错误或警告消息。但是,应用程序一旦加载,就会崩溃,原因如下: 更新:我已经完成了所有工作,但是我的TableView没有显示任何数据,应用程序也没有响应以下断点 - (NSInteger)numberOfSectionsInTableView:(UITableView *)table { return [[fetchedResultsController sections] count]; } - (
- (NSInteger)numberOfSectionsInTableView:(UITableView *)table {
return [[fetchedResultsController sections] count];
}
- (NSInteger)tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section {
id <NSFetchedResultsSectionInfo> sectionInfo = [[fetchedResultsController sections] objectAtIndex:section];
return [sectionInfo numberOfObjects];
}
- (void)viewDidUnload {
[super viewDidUnload];
self.tableView = nil;
[[NSNotificationCenter defaultCenter] removeObserver:self name:NSManagedObjectContextDidSaveNotification object:self.managedObjectContext];
[self.tableView reloadData];
}
- (UITableViewCell *)tableView:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *kCellIdentifier = @"SongCell";
UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:kCellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:kCellIdentifier] autorelease];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.textLabel.font = [UIFont boldSystemFontOfSize:14];
}
Incident *incident = [fetchedResultsController objectAtIndexPath:indexPath];
cell.textLabel.text = [NSString stringWithFormat:NSLocalizedString(@"#%d %@", @"#%d %@"), incident.title];
return cell;
}
- (void)tableView:(UITableView *)table didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[table deselectRowAtIndexPath:indexPath animated:YES];
self.detailController.incident = [fetchedResultsController objectAtIndexPath:indexPath];
[self.navigationController pushViewController:self.detailController animated:YES];
}
谢谢
更新:下面是不响应断点的新代码
- (NSInteger)numberOfSectionsInTableView:(UITableView *)table {
return [[fetchedResultsController sections] count];
}
- (NSInteger)tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section {
id <NSFetchedResultsSectionInfo> sectionInfo = [[fetchedResultsController sections] objectAtIndex:section];
return [sectionInfo numberOfObjects];
}
- (void)viewDidUnload {
[super viewDidUnload];
self.tableView = nil;
[[NSNotificationCenter defaultCenter] removeObserver:self name:NSManagedObjectContextDidSaveNotification object:self.managedObjectContext];
[self.tableView reloadData];
}
- (UITableViewCell *)tableView:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *kCellIdentifier = @"SongCell";
UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:kCellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:kCellIdentifier] autorelease];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.textLabel.font = [UIFont boldSystemFontOfSize:14];
}
Incident *incident = [fetchedResultsController objectAtIndexPath:indexPath];
cell.textLabel.text = [NSString stringWithFormat:NSLocalizedString(@"#%d %@", @"#%d %@"), incident.title];
return cell;
}
- (void)tableView:(UITableView *)table didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[table deselectRowAtIndexPath:indexPath animated:YES];
self.detailController.incident = [fetchedResultsController objectAtIndexPath:indexPath];
[self.navigationController pushViewController:self.detailController animated:YES];
}
根据发布的代码和问题描述,我怀疑
categoryEntityDescription
属性返回nil
n实体描述?!?由于核心数据的原因,它们已经在内存中,保留它们是一种浪费,如果核心数据希望在某个时候发布它们,这可能会导致问题
NSEntityDescription
,同样,不要保留NSEntityDescription
您是否100%肯定n实体描述
不是零?你在调试器中确认了吗?您是否使用新检索的NSEntityDescription
对其进行了测试
使现代化
您需要学习使用调试器,因为它将解决大多数编码问题。在此方法中放置断点,并在调试器中运行代码。然后,当执行在该断点停止时,您可以检查变量的值并了解它们当前设置为什么。这将证实或否认你对什么是零和什么不是零的怀疑
如果未能在
NSFetchRequest
中设置实体
,则会出现此错误,根据您的代码,这意味着在调用显示的代码之前未设置保留属性。因为您手动添加了模型文件,编译源代码步骤中的.xcdatamodel文件是否在目标中
转到Xcode中“组和文件”窗格中的“目标”条目,然后单击“公开三角形”。然后单击应用程序的“披露三角”。然后检查它是否在编译源代码中。如果没有,右键单击编译源代码并选择“添加->现有文件…”并添加它
根据更新进行编辑:
更新:这是新的代码
不响应断点
- (NSInteger)numberOfSectionsInTableView:(UITableView *)table {
return [[fetchedResultsController sections] count];
}
- (NSInteger)tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section {
id <NSFetchedResultsSectionInfo> sectionInfo = [[fetchedResultsController sections] objectAtIndex:section];
return [sectionInfo numberOfObjects];
}
- (void)viewDidUnload {
[super viewDidUnload];
self.tableView = nil;
[[NSNotificationCenter defaultCenter] removeObserver:self name:NSManagedObjectContextDidSaveNotification object:self.managedObjectContext];
[self.tableView reloadData];
}
- (UITableViewCell *)tableView:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *kCellIdentifier = @"SongCell";
UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:kCellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:kCellIdentifier] autorelease];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.textLabel.font = [UIFont boldSystemFontOfSize:14];
}
Incident *incident = [fetchedResultsController objectAtIndexPath:indexPath];
cell.textLabel.text = [NSString stringWithFormat:NSLocalizedString(@"#%d %@", @"#%d %@"), incident.title];
return cell;
}
- (void)tableView:(UITableView *)table didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[table deselectRowAtIndexPath:indexPath animated:YES];
self.detailController.incident = [fetchedResultsController objectAtIndexPath:indexPath];
[self.navigationController pushViewController:self.detailController animated:YES];
}
您的视图控制器是否设置为您的
UITableView
的UITableViewDataSource
/UITableViewDelegate
?如果没有,这些方法将不会被调用。我看到,当给定给获取请求的NSEntityDescription
为nil时,会发生这种情况。最可能的原因是您的模型实体的名称与您提供给entityForName
的名称不同。除此之外,这可能是核心数据堆栈配置中的错误或缺少数据模型,但作为第一步,我建议将entityForName
的结果存储在局部变量中,并在其中中断,以确保它不是零。将相关代码张贴在提取发生的位置。我确实手动添加了它,但在本例中,它已经在“Compile Sources”文件夹中。如果你查看Xcode构建的.app包,是否有一个.mom文件?是的,有-我设法解决了部分问题,但是,.xcdatamodel中我的一个类引用拼写错误:)唯一的问题是,它现在加载时没有崩溃,并且应该是解析的,但是表视图保持空白。有什么想法吗?我得到了一个新的错误(见简介编辑),但我把它注释掉了,以使它能够正常工作;它被击中了吗?i、 e.NSFetchedResultsController
是否实际正在提取?否则,请在各种UITableDataSource
/UITableViewDelegate
方法中设置断点。他们被击中了吗?如果是,他们将返回什么?显示numberOfSectionsInTableView:
和tableView:numberofrowsinssection:
的代码。正如我前面提到的,大部分代码来自苹果的TopSongs示例,所以我不确定那里发生了什么。至于categoryEntityDescription,它是在Category类中设置的。等等,你指的是什么“缓存”?我所做的就是从TopSongs的Apple Demo应用程序中复制代码,并重命名方法以适合我的项目。至于你剩下的建议,我现在会研究一下,谢谢。我检查了TopSongs应用程序-它们保留了N实体描述。有趣的至于测试NSEntityDescription不是零,您希望我如何测试它?(对不起,我在这方面有点新手)
- (UITableViewCell *)tableView:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)indexPath
- (void)tableView:(UITableView *)table didSelectRowAtIndexPath:(NSIndexPath *)indexPath