Pur*_*rva 0 iphone core-data uitableview
我已经在核心数据中执行了保存操作并且它已成功完成.它存储了数据.我还将数据提取到日志中.这是我在日志中获取数据的代码,但我不知道如何在TableView中获取此数据.
NSError *error;
DemoAppCoreDataAppDelegate *appdelegate = (DemoAppCoreDataAppDelegate *)[[UIApplication sharedApplication]delegate];
NSManagedObjectContext *context = [appdelegate managedObjectContext];
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc]init];
NSEntityDescription *entity = [NSEntityDescription entityForName: @"Employee" inManagedObjectContext:context];
[fetchRequest setEntity:entity];
NSArray *fetchedobject = [context executeFetchRequest:fetchRequest error:&error];
tablearray = [[NSMutableArray alloc] initWithArray:fetchedobject copyItems:YES];
for (NSManagedObject *info in fetchedobject ) {
NSLog(@ "%@",[info valueForKey:@"name"] );
}
[fetchRequest release];
Run Code Online (Sandbox Code Playgroud)
我建议使用一个NSFetchedResultsController.
Apple在文档中提供了完整的示例代码NSFetchedResultsController
该NSFetchedResultsController专门到的tableView和核心数据之间的工作英寸 它使一切变得更容易.
例如,当您从核心数据添加或删除对象时,它将自动插入和删除行.为此,您必须实现NSFetchedResultsControllerDelegate协议.完整的示例代码在协议文档中
| 归档时间: |
|
| 查看次数: |
1702 次 |
| 最近记录: |