Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6684483
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:56:43+00:00 2026-05-26T04:56:43+00:00

I have set up the following relationships (the Site entity isn’t important here): https://i.stack.imgur.com/6pzHn.gif

  • 0

I have set up the following relationships (the Site entity isn’t important here): https://i.stack.imgur.com/6pzHn.gif

The main thing here is that I have a Find entity which can have many FindPhotos. In my app there is an editing screen, where you can edit a Find’s attributes and also add/remove its FindPhotos. Here’s the important code:

/* tapping the Save button */
- (IBAction)saveFind:(id)sender {
    [[self find] setFindName:findName];
    [[self find] setNotes:[self notes]];
    /* etc... */

    NSError *error;
    [[self context] save:&error];
    if (error) {
        NSLog(@"Error while saving find: %@", error);
    }

    [[self presentingViewController] dismissModalViewControllerAnimated:YES];
}

- (void) imagePickerController: (UIImagePickerController *) picker didFinishPickingMediaWithInfo: (NSDictionary *) info {   
    NSString *mediaType = [info objectForKey: UIImagePickerControllerMediaType];
    UIImage *originalImage, *editedImage, *imageToSave;

    // Handle a still image capture
    if (CFStringCompare ((__bridge CFStringRef) mediaType, kUTTypeImage, 0) == kCFCompareEqualTo) {

        editedImage = (UIImage *) [info objectForKey:UIImagePickerControllerEditedImage];
        originalImage = (UIImage *) [info objectForKey:UIImagePickerControllerOriginalImage];

        if (editedImage) {
            imageToSave = editedImage;
        } else {
            imageToSave = originalImage;
        }

        NSString *documentsDirectory = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
        NSString *pathName = [NSString stringWithFormat:@"/Photo%i.jpg", [NSString UUIDString]];
        NSString *jpgPath = [documentsDirectory stringByAppendingPathComponent:pathName];

        [UIImageJPEGRepresentation(imageToSave, 1.0) writeToFile:jpgPath atomically:YES];

        NSData * thumbnail = UIImageJPEGRepresentation([originalImage thumbnailImage:100 transparentBorder:0 cornerRadius:0 interpolationQuality:kCGInterpolationMedium], 1.0);

        FindPhoto *photo = [NSEntityDescription insertNewObjectForEntityForName:@"FindPhoto" inManagedObjectContext:[self context]];

        [photo setThumbnail:thumbnail];
        [photo setPath:jpgPath];
        [photo setFind:[self find]];

        [[self find] addPhotosObject:photo];
    }

    [picker dismissModalViewControllerAnimated: YES];
}

/* tapping the Cancel button */
- (IBAction)cancel:(id)sender {
    [[self presentingViewController] dismissModalViewControllerAnimated:YES];
}

/* deleting a photo */
- (void)photoWasDeleted:(MWPhoto *)mwphoto {
    for (FindPhoto *photo in [[self find] photos]) {
        if ([[photo path] isEqualToString:[mwphoto photoPath]]) {
            [[self find] removePhotosObject:photo];
            NSLog(@"Photo deleted");
            return;
        }
    }
}

By tapping the Save button, the saveFind method is called, which saves the context.
The problem is that even if I tap the Cancel button, the FindPhotos will still show as deleted/added, even if I don’t save the context.

I want the FindPhoto entities to be changed for the Find only when I tap the Save button. Can anyone recommend me a way to handle this kind of situation?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T04:56:43+00:00Added an answer on May 26, 2026 at 4:56 am

    There are several ways to solve this problem:

    1. create an additional context for adding the new objects, on cancel dismiss the context, on save merge the context with the main context

    2. Use an undo manager, on cancel revert any changes. Use undo grouping to group all changes

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following relationships set up: A HABTM B B belongsTo C C
I have the following relationships set up: Teacher: var $hasAndBelongsToMany = array( 'Classroom' =>
I'm trying to map a Dictionary containing Lists. I have the following set of
I'm using log4Net for my logging. I also have the following set... <log4net debug=true>
I have implemented the following set up (after being requested): slideshow of images changing,
I have just set up ruby in Aptana studio and am getting the following
I have a set of vertically ordered elements. They are displayed with the following
I'm trying to do the following: I have a set of images and select
I have the following regex set as the ValidationExpression property on a RegularExpressionValidator in
I have the following code set up in my Startup IDictionary<string, string> properties =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.