0
我有一个非常基本的CoreData支持的iPhone应用程序。在我强制应用程序生成sqlite文件后,我拿了它,并预先填充一个记录,以测试它加载到tableview中。CoreData不提取任何行
虽然我碰到了一个障碍,因为CoreData似乎没有在表格中找到该行。
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return [fetchedResultsController sections] count];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
id <NSFetchedResultsSectionInfo> sectionInfo = [[fetchedResultsController sections] objectAtIndex:section];
return [sectionInfo numberOfObjects];
}
第一函数总是返回一个和第二函数总是返回零。由于tableview认为没有行,因此它从不碰到cellForRowAtIndexPath,所以我的数据都没有加载。
我可以,但是,看到在viewDidLoad中我的表结构与下面的代码:现在
if(!managedObjectContext){
managedObjectContext = [(AppDelegate *)[[UIApplication sharedApplication] delegate] managedObjectContext];
}
NSFetchRequest *request = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Assessment" inManagedObjectContext:managedObjectContext];
[request setEntity:entity];
for (NSPropertyDescription *property in entity)
{
NSLog(@"%@", property.name);
}
NSError *error = nil;
NSMutableArray *mutableFetchResults = [[managedObjectContext executeFetchRequest:request error:&error] mutableCopy];
[request release];
,这让我感到没有在我的代码的其余不断产生NSFetchRequest因为我从不打cellForRowAtIndex。但我也基于食谱示例中的大部分代码,它看起来像以同样的方式加载(并且它实际上工作)。
我敢肯定我在这里错过了一些明显的东西,有人可以指出我在正确的方向吗?
该代码可以在其中找到完整here。
谢谢!我不知何故忽略了设置抓取的结果控制器。知道这是简单的事情。 – 2010-07-30 20:22:46