Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Build a Diary App Using Core Data Custom Detail View Controller Implementing a UIImagePickerController

Anthony Ho
Anthony Ho
10,228 Points

When I edit the diary entries, the picked image dissappears.

The application can't hold the image data of the original picked image. It disappears when the user wants to edit and have to pick the image again.

-(void)insertDiaryEntry {
    ZMCoreDataStack *coreDataStack =[ZMCoreDataStack defaultStack];
    ZMDiaryEntry *entry = [NSEntityDescription insertNewObjectForEntityForName:@"ZMDiaryEntry" inManagedObjectContext:coreDataStack.managedObjectContext];
    entry.body = self.textView.text;
    entry.date = [[NSDate date] timeIntervalSince1970];
    entry.imageData =  UIImageJPEGRepresentation(self.pickedImage, 0.75);
    [coreDataStack saveContext];

}
-(void) updateDiaryEntry{
    ZMCoreDataStack *coreDataStack = [ZMCoreDataStack defaultStack];
    self.entry.body=self.textView.text;
    self.entry.imageData = UIImageJPEGRepresentation(self.pickedImage, 0.75);

    [coreDataStack saveContext];
}

1 Answer