I’m having some trouble with an iPhone app that I’m making. I have two entities in my xcdatamodel: Team and Camera. Each Team has a Camera, and every Camera belongs to a Team. I have correctly implemented the Team entity into my navigation-based app, so that I can add teams to a table view. However, when I go to click on the disclosure button and call the team’s Camera entity so I take a picture and store it, my app crashes.
Here’s the code from my RootViewController.m that is relevant to Camera entity.
-(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];
}
The “initWithRootController…” is implemented this way in my CameraDetailView.m:
-(id)initWithRootController:(RootViewController *)aRootController team:(NSManagedObject *)aTeam /*camera:(NSManagedObject *)aCamera*/ {
if ((self = [super init])) {
self.rootController = aRootController;
self.team = aTeam;
}
return self;
}
There error occurs when
- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath {
is called.
Does anybody know what I’m doing wrong?
I discovered a problem with the links in my NIB file by using a try/catch block. Solution: Always put your code in try/catch blocks first to catch the error!