我有以下2實體在我的xcdatamodel:ADDOBJECT一/多到很多核心數據關係爲iPhone
矩陣 1.1屬性 名稱 1.2關係 MatrixToProcess 目的地是:過程 倒數:ProcessToMatrix 的一對多的關係被檢查 刪除規則是級聯
工藝 2.1屬性 名稱 2.2關係 ProcessToMatrix 的目標是:矩陣 倒數:MatrixToProcess 的一對多關係不檢查 刪除規則是抵消
我可以成功添加一個新的Matrix,它被添加並在UITableView中正確顯示。
我可以成功添加一個新的進程,但是, 所有必要的信息都會被添加到數據庫中,並從矩陣表中除去Z_PK值。 即iPhone模擬器中的sqlite數據庫將創建新的進程名稱,但不會將任何信息輸入到ZPROCESSTOMATRIX列中。如果我手動插入關聯的矩陣名稱Z_PK值,則一切正常。
我在努力。不完全理解如何在Process * newProcess = [NSEntityDescription insertNewObjectForEntityForName:@「Process」inManagedObjectContext:self.managedObjectContext];下添加addObject。 這是我使用的代碼:
- (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];
}
任何幫助和/或方向,將不勝感激。
我已經在xcdatamodel中設置了關係。有什麼我需要添加代碼來設置新的過程和矩陣之間的關係。 我爲模糊不清,但我是iphone新手。 我很感謝您的迴應。 – 2010-01-07 01:05:57
讓我目瞪口呆的是[Airport.Board.flights addObject:newFlight];線。這條線我需要什麼。 – 2010-01-07 01:08:49
是的,這正是你需要的(除非你將Matrix對象添加到新的Process對象中)。第一步是從數據模型生成Class文件。 – gerry3 2010-01-07 01:11:32