为iPhone核心数据中的一对多关系添加对象
我的xcdatamodel中有以下两个实体:为iPhone核心数据中的一对多关系添加对象,iphone,core-data,insert,Iphone,Core Data,Insert,我的xcdatamodel中有以下两个实体: 母体 1.1属性 名称 1.2关系 矩阵过程 目标是:进程 相反的是:ProcessToMatrix 已检查多对多关系 删除规则是级联的 过程 2.1属性 名称 2.2关系 过程矩阵 目的地是:矩阵 相反的是:MatrixToProcess 未检查对多关系 删除规则无效 我可以成功添加一个新矩阵,该矩阵已添加并在UITableView中正确显示 但是,我可以成功地添加新流程, 除矩阵表中的Z_PK值外,所有必要的信息都添加到数据库中。 i、 e.iP
- (void)addProcess:(id)sender {
ProcessAddViewController *addController = [[ProcessAddViewController alloc] initWithNibName:@"ProcessAddView" bundle:nil];
addController.delegate = self;
Process *newProcess = [NSEntityDescription insertNewObjectForEntityForName:@"Process" inManagedObjectContext:self.managedObjectContext];
addController.process = newProcess;
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:addController];
[self presentModalViewController:navigationController animated:YES];
[navigationController release];
[addController release];
}
- (void)processAddViewController:(ProcessAddViewController *)processAddViewController didAddProcess:(Process *)process {
if (process) {
[self showProcess:process animated:NO];
}
[self dismissModalViewControllerAnimated:YES];
}
- (void)showProcess:(Process *)process animated:(BOOL)animated {
RootViewController *rootViewController = [[RootViewController alloc] initWithStyle:UITableViewStyleGrouped];
rootViewController.managedObjectContext = self.managedObjectContext;
if(entitySearchPredicate == nil)
{
NSMutableArray* mutableFetchResults = [CoreDataHelper getObjectsFromContext:self.entityName :@"displayOrder" :YES :managedObjectContext];
[self setEntityArray:mutableFetchResults];
[mutableFetchResults release];
}
else
{
NSMutableArray* mutableFetchResults = [CoreDataHelper searchObjectsInContext:self.entityName :entitySearchPredicate :@"displayOrder" :YES :managedObjectContext];
[self setEntityArray:mutableFetchResults];
[mutableFetchResults release];
}
[rootViewController release];
}
任何帮助和/或指导都将不胜感激。您需要设置新流程和矩阵之间的关系 结帐到 更新 假设您已经为流程和矩阵生成了类文件,并且流程与名为“processToMatrix”的矩阵有关系,设置关系的代码如下:
newProcess.processToMatrix = matrix;
其中“矩阵”是应与新流程对象关联的矩阵对象。我已在xcdatamodel中设置了关系。我是否需要在代码中添加一些东西来设置新流程和矩阵之间的关系。我对这种含糊不清表示歉意,但我对iphone的开发还不熟悉。感谢您的回复。令我震惊的是[Airport.Board.flights addObject:newFlight];线路。在这行中我需要什么。是的,这正是您需要的(除非您将在新流程对象中向该集合添加一个矩阵对象)。第一步是从数据模型生成类文件。你能用代码删除这些注释吗?没有什么有用的。如果您有更多代码,请编辑原始问题并将其添加到那里。此外,您可能需要设置问题代码的格式,以使其可读。同样,您可以用代码删除这些注释吗?它们没有用处。如果您有更多代码,请编辑原始问题并将其添加到那里。另外,请修复问题中的代码格式!