詳細ビュー コントローラーで新しい子エンティティを作成します。だから私はセグエを送ります
detailedViewController.managedObjectContext = managedObjectContext;
detaledViewController.parent = currentParent; //type of Parent
detailViewController.m で
-(IBAction)saveChildObj:(id)sender{
self.childEntity= [NSEntityDescription insertNewObjectForEntityForName:@"ChildEntity" inManagedObjectContext:self.managedObjectContext];
self.childEntity.childEntityName= self.childEntityName.text;
[self.parent addMyChildObject:self.childEntity];
[self.managedObjectContext performBlockAndWait:^{
NSError *error = nil;
BOOL saved = [self.managedObjectContext save:&error];
if (!saved) {
// do some real error handling
NSLog(@"Could not save Date due to %@", error);
}
[[osCoreDataController sharedImstanse] saveMasterContext];
}];
[self.navigationController popViewControllerAnimated:YES];
}
addMyChildEntity を呼び出した後、テキストにエラーがあります:
2013-06-09 22:21:39.191 FindYourMedicine[2476:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Illegal attempt to establish a relationship 'parent' between objects in different contexts (source = <ChildEntity: 0x8acbf30> (entity: ChildEntity; id: 0x8accb10 <x-coredata:///ChildEntity/t8DB5D204-A359-45E5-8F2B-8DE6A26D245C3> ; data: {
date = (
);
parent= nil;
childEntityName= fgh;
times = (
);
}) , destination = <Parent: 0x8a9a9a0> (entity: Parent; id: 0x8a99cb0 <x-coredata://48BBE637-9D07-4529-9C6A-DCCF118B4717/Disease/p2> ; data: {
parentName = "\U0430\U0441\U0442\U043c\U0430";
childEntity= (
);
コアデータの構造が多すぎる: 親 ->> 子 ->> 回
managedObjectContext.parantContext を使用しようとしましたが、何も役に立ちません