-1

我有以下 json 文件

 {
   items = ({“text1” = “lorem ipsum”;},
            {“text2” = “lorem ipsum”;});
   id = 0;
   title = “item0”;
 },
 {
   items = ({“text1” = “lorem ipsum”;},
            {“text2” = “lorem ipsum”;});
   id = 1;
   title = “item1”;
 }

我将核心数据用于持久性标题是第一个实体的名称也是表视图的部分名称我想将项目数组填充到部分中,例如部分标题 =“items1”包含 2 个项目 text1 和 text2 我的问题是单元格如何将该信息添加到单元格中但使用核心数据。我的第一次尝试是创建一个具有可转换类型的实体,例如在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"];
   }
}

关于这个话题的任何想法?

4

2 回答 2

1

我认为您可以使用NSFetchedResultsController. 查看Apple 文档了解更多信息。

于 2013-06-18T06:04:43.630 回答
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;
}
于 2013-06-18T06:21:15.133 回答