2012-02-20 74 views
0

我在使用iPhone應用程序時遇到了一些麻煩。我的xcdatamodel中有兩個實體:Team和Camera。每個團隊都有一個相機,每個相機都屬於一個團隊。我已經在我的基於導航的應用程序中正確實施了團隊實體,以便我可以將團隊添加到表格視圖。但是,當我點擊披露按鈕並調用團隊的相機實體以拍攝照片並存儲它時,我的應用程序崩潰。核心數據詳細視圖故障

下面是我的RootViewController.m中與Camera實體相關的代碼。

-(void)insertCameraWithTeam:(NSManagedObject *)team picture:(NSString *)picture { 
NSManagedObjectContext *context = [self.fetchedResultsController managedObjectContext]; 
NSManagedObject *camera = [NSEntityDescription insertNewObjectForEntityForName:@"Camera" inManagedObjectContext:context]; 
[camera setValue:picture forKey:@"picture"]; 
} 


#pragma mark - 
#pragma mark Table view data source 

- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath { 
NSManagedObject *team = [self.fetchedResultsController objectAtIndexPath:indexPath]; 
CameraDetailView *cameraDetailView = [[CameraDetailView alloc] initWithRootController:self team:team]; 
[self.navigationController presentModalViewController:cameraDetailView animated:YES]; 
[cameraDetailView release]; 
} 

的 「initWithRootController ......」 實現我的CameraDetailView.m是這樣的:當

- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath { 

被稱爲發生

-(id)initWithRootController:(RootViewController *)aRootController team:(NSManagedObject *)aTeam /*camera:(NSManagedObject *)aCamera*/ { 
if ((self = [super init])) { 
self.rootController = aRootController; 
self.team = aTeam; 
} 
return self; 
} 

有錯誤。

有人知道我在做什麼錯嗎?

+0

它如何崩潰?如果你在你的問題中包含崩潰日誌,它可以幫助你更容易。 – jrturton 2012-02-20 08:39:01

+0

好吧,您的評論最終幫助我解決了我自己的XD上的問題。調試器除了通用的SIGABORT外沒有給我任何東西,所以我把有問題的方法放在try/catch塊中,發現我的NIB連線不正確。感謝您的評論,下次我會記得在原始文章中包含崩潰日誌! – Egdod 2012-02-20 17:57:28

回答

0

我發現了一個問題,使用try/catch塊在我的NIB文件中的鏈接。解決方案:始終將您的代碼放入try/catch塊以捕捉錯誤!