0

我正在尝试使用以下代码用 NSFetchRequest 填充具有 2 个实体的表视图:

@property (strong) NSMutableArray *forms;


    NSManagedObjectContext *managedObjectContext = [self managedObjectContext];
    NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] initWithEntityName:@"names"];
    NSFetchRequest *fetchRequest2 = [[NSFetchRequest alloc] initWithEntityName:@"forms"];

    self.forms = [[managedObjectContext executeFetchRequest:fetchRequest error:nil] mutableCopy];
    self.forms = [[managedObjectContext executeFetchRequest:fetchRequest2 error:nil] mutableCopy];


    [self.tableView reloadData];

现在我知道 self.forms 被第二次提取覆盖了,但我不知道如何完成将所有内容放入 self.forms 数组

4

1 回答 1

2

尝试这个:

self.forms = [[managedObjectContext executeFetchRequest:fetchRequest error:nil] mutableCopy];
[self.forms addObjectsFromArray:[[managedObjectContext executeFetchRequest:fetchRequest2 error:nil] mutableCopy]];
于 2013-07-18T17:42:30.353 回答