我有以下json文件
{
items = ({“text1” = “lorem ipsum”;},
{“text2” = “lorem ipsum”;});
id = 0;
title = “item0”;
},
{
items = ({“text1” = “lorem ipsum”;},
{“text2” = “lorem ipsum”;});
id = 1;
title = “item1”;
}
我正在使用核心数据进行持久化标题是第一个实体的名称也是表视图的部分名称我希望将项目数组填充到部分例如section title =“items1”包含2个项目text1和text2 my问题在于细胞如何将这些信息添加到细胞中但是有核心数据。我首先尝试创建一个具有可转换类型的实体,例如在 NSManagedObject 类
内部self.title = [dictionary objectForKey:@"title"];
NSArray *items = [dictionary objectForKey:@"items"];
if ([items isKindOfClass:[NSArray class]])
{
for (NSDictionary *item in items)
{
self.arr = [clip objectForKey:@"text1"];
}
}
关于这个主题的任何想法?
答案 0 :(得分:1)
我认为你可以使用NSFetchedResultsController
。查看Apple Docs了解详情。
答案 1 :(得分:0)
我正在使用以下代码获取数据
- (NSFetchedResultsController *)fetchedResultsController
{
if (!_fetchedResultsController)
{
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"List" inManagedObjectContext:self.managedObjectContext];
[fetchRequest setEntity:entity];
NSSortDescriptor *authorDescriptor = [[NSSortDescriptor alloc] initWithKey:@"test" ascending:YES];
NSSortDescriptor *titleDescriptor = [[NSSortDescriptor alloc] initWithKey:@"title" ascending:YES];
NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:authorDescriptor, titleDescriptor, nil];
[fetchRequest setSortDescriptors:sortDescriptors];
_fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:self.fetchRequest managedObjectContext:self.managedObjectContext sectionNameKeyPath:self.sectionNameKeyPath cacheName:self.cacheName];
_fetchedResultsController.delegate = self;
[_fetchedResultsController performFetch:nil];
}
return _fetchedResultsController;
}