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 7855965
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T20:32:35+00:00 2026-06-02T20:32:35+00:00

So, the app that I’m writing allows the user to upload a photo from

  • 0

So, the app that I’m writing allows the user to upload a photo from their camera roll, and it displays in a UIImageView. I have a “Save” button, that allows the images to be saved when pressed. I also have an “Edit” button, when tapped, it allows the user to tap on the photo and it will be deleted. This is where I’m having issues.

On test runs when I add in three images, hit the save button, then delete them, they delete perfectly. I can completely close and relaunch the app and the images are no longer there. But, if I add in three images, hit the save button then close and relaunch the app, then try to delete the photos, it does not work at all. The images disappear from the screen, but load again on relaunch. Very strange. I’m totally new to Objective-C, I’m surprised that I even made it this far, so I’m having issues figuring out how to delete it from the array.

I have NSLog(@"User Clicked Yes. Deleting index %d of %d", alertView.tag, [array count]); in ym code, and when I delete it before closing the app, it displays that the array count has objects in it. When I run it from Xcode again and try to delete a picture thats already been saved, it indicates that the array count = 0. The objects are not in the array on relaunch. So, the issue is that the objects in the array aren’t being saved properly. I have no idea why not though, I thought I was saving them correctly. This is how I add them into the array:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)img editingInfo:(NSDictionary *)editInfo {
    if (imageView.image == nil) {
        imageView.image = img;

        [self.array addObject:imageView];

        [picker dismissModalViewControllerAnimated:YES];
        [self.popover dismissPopoverAnimated:YES];

        return;

    }

    if (imageView2.image == nil) {
        imageView2.image = img;
        NSLog(@"The image is a %@", imageView);
        [self.array addObject:imageView2];

        [picker dismissModalViewControllerAnimated:YES];
        [self.popover dismissPopoverAnimated:YES];

        return;
    }
   ...
     ...
-(IBAction)saveButtonPressed:(id)sender {
    NSString *docsDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask,YES) objectAtIndex:0];

    NSLog(@"Image view array before saving = %@", self.array);

    for (UIImageView *imageViewToSave in self.array) {

        NSInteger tag = imageViewToSave.tag;
        UIImage *image = imageViewToSave.image;
        NSString *imageName = [NSString stringWithFormat:@"Image%i.png",tag];

        NSString *imagePath = [docsDir stringByAppendingPathComponent:imageName];

        NSLog(@"Saving %@ to %@", image, imagePath);

        [UIImagePNGRepresentation(image) writeToFile:imagePath atomically:NO];
    }
    NSLog(@"Save Button Pressed");
}

I thought that this would save the objects that were placed into the array, but apparently not. I have no idea how else to go about doing this.

And just for reference, I threw my .h and .m files in a wiki. Here is my entire .h file:
github.com/Joey502/Test-Thing/wiki/.h-Class-File And here is my entire .m file: github.com/Joey502/Test-Thing/wiki/.m-Class-File

  • 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-06-02T20:32:36+00:00Added an answer on June 2, 2026 at 8:32 pm

    The problem is in your viewDidLoad method, there you have initialised self.array but when loading the images into your UIImageViews you have forgotten to add them to the array, which is why the delete function isn’t working. Your delete function is trying to delete an object from an array that is empty.

    Inside your if statements you need to add the UIImageView to self.array (Note: you’ll need to change self.array to a NSMutableArray for this particular method to work)

    if (!imageView.image) {
        imageView.image = loadedImage;
        [self.array addObject:imageView];
    } 
    else if (!imageView2.image) {
        imageView2.image = loadedImage;
        [self.array addObject:imageView2];
    }
    

    and so on.

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

Sidebar

Related Questions

The app that I'm working on allows the user to pick an image from
I am writing an app that allows a user to set the phone's wallpaper
I have a simple app that reads internet resource and displays the information in
I am developing an app that have to stream live audio (from a m3u
I'm building an app that takes status updates from several Social Media. Already have
I have a web app that works fine from all browsers (IE9, Firefox, Chrome,
I have inherited an app that generates a large array for every user that
I have an app that a user will be able to take pictures with.
I have a app that loads some json from my php web service. This
I'm writing an app that allows me to send a command through TCP/IP by

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.