My application allows a user to take an image with the camera or select an image from their photo library.
Inside didFinishPickingMediaWithInfo I get the image and save it to the database using Core Data.
When I get an image from the photo library I see the following NSFetchedResultsControllerDelegate methods being called:
– controllerWillChangeContent: – controller:didChangeObject:atIndexPath:forChangeType:newIndexPath: – controllerDidChangeContent:
When I get an image using the camera I do not see the above methods being called.
Below is my code:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage* selectedImage = [info objectForKey:UIImagePickerControllerOriginalImage];
// Create an image object for the new image.
NSManagedObject *image = [NSEntityDescription insertNewObjectForEntityForName:@"Image" inManagedObjectContext:managedObjectContext];
// Set the image for the image managed object.
[image setValue:[selectedImage scaleAndCropImageToScreenSize] forKey:@"image"];
// Create a thumbnail version of the image.
UIImage *imageThumbnail = [selectedImage thumbnailImage:50.0F];
// Create a new note
Note *note = [NSEntityDescription insertNewObjectForEntityForName:@"Note" inManagedObjectContext:managedObjectContext];
NSDate *now = [[NSDate alloc] init];
note.createdDate = now;
note.lastModifiedDate = now;
[now release];
note.thumbnail = imageThumbnail;
note.image = image;
[self dismissModalViewControllerAnimated:YES];
[picker release];
}
- (void)controllerWillChangeContent:(NSFetchedResultsController *)controller {
debug(@"controllerWillChangeContent");
[self.tableView beginUpdates];
}
- (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type newIndexPath:(NSIndexPath *)newIndexPath {
debug(@"NSFetchedResultsController didChangeObject");
UITableView *tableView = self.tableView;
switch(type) {
case NSFetchedResultsChangeInsert:
[tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath] withRowAnimation:UITableViewRowAnimationFade];
break;
case NSFetchedResultsChangeDelete:
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
break;
case NSFetchedResultsChangeUpdate:
[self configureCell:[tableView cellForRowAtIndexPath:indexPath] atIndexPath:indexPath];
break;
case NSFetchedResultsChangeMove:
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
[tableView reloadSections:[NSIndexSet indexSetWithIndex:newIndexPath.section] withRowAnimation:UITableViewRowAnimationFade];
break;
}
NSError *error = nil;
if (managedObjectContext != nil) {
if ([managedObjectContext hasChanges] && ![managedObjectContext save:&error]) {
error(@"An error occured saving the managedObjectContext. %@, %@", error, [error userInfo]);
} else {
debug(@"Sucessfull saved managedObjectContext");
}
}
}
- (void)controller:(NSFetchedResultsController *)controller didChangeSection:(id <NSFetchedResultsSectionInfo>)sectionInfo atIndex:(NSUInteger)sectionIndex forChangeType:(NSFetchedResultsChangeType)type {
switch(type) {
case NSFetchedResultsChangeInsert:
[self.tableView insertSections:[NSIndexSet indexSetWithIndex:sectionIndex] withRowAnimation:UITableViewRowAnimationFade];
break;
case NSFetchedResultsChangeDelete:
[self.tableView deleteSections:[NSIndexSet indexSetWithIndex:sectionIndex] withRowAnimation:UITableViewRowAnimationFade];
break;
}
}
- (void)controllerDidChangeContent:(NSFetchedResultsController *)controller {
[self setControllerTitle];
[self.tableView endUpdates];
debug(@"controllerDidChangeContent");
}
Here are my logs from when I use the camera to get an image
2010-08-25 19:11:27.770 File:NoteListViewController.m Line:122 Add Note - Camera Selected 2010-08-25 19:11:27.817 VisualNotes[1031:307] Using two-stage rotation animation. To use the smoother single-stage animation, this application must remove two-stage method implementations. 2010-08-25 19:11:27.821 VisualNotes[1031:307] Using two-stage rotation animation is not supported when rotating more than one view controller or view controllers not the window delegate
Here are my logs from when I select a photo library image
2010-08-25 19:11:44.396 VisualNotes[1031:307] File:NoteListViewController.m Line:128 Add Note - Photo Library Selected 2010-08-25 19:11:44.417 VisualNotes[1031:307] Using two-stage rotation animation. To use the smoother single-stage animation, this application must remove two-stage method implementations. 2010-08-25 19:11:44.420 VisualNotes[1031:307] Using two-stage rotation animation is not supported when rotating more than one view controller or view controllers not the window delegate 2010-08-25 19:11:48.144 VisualNotes[1031:307] File:NoteListViewController.m Line:315 controllerWillChangeContent 2010-08-25 19:11:48.155 VisualNotes[1031:307] File:NoteListViewController.m Line:321 NSFetchedResultsController didChangeObject 2010-08-25 19:11:48.310 VisualNotes[1031:307] File:NoteListViewController.m Line:350 Successfully saved managedObjectContext 2010-08-25 19:11:48.333 VisualNotes[1031:307] File:NoteListViewController.m Line:370 controllerDidChangeContent