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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T06:39:10+00:00 2026-06-01T06:39:10+00:00

I need to call removeObject in one of my methods, but I can’t figure

  • 0

I need to call removeObject in one of my methods, but I can’t figure out how to do this correctly. I’m very new to Objective-C, and am still learning the basics. I have an app that behaves somewhat like a photo gallery, and displays UIImageViews. I’m implementing the option to have the user delete photos from their gallery. To accomplish this, I decided to place an invisible button over each picture. When the user hits an “Edit” button, the hidden delete button over each picture becomes active (I’m using the same IBOutlet over each of the hidden buttons, for simplicity). When the user taps the button over the picture, an alert view appears asking if they really want to delete it. If they click yes, deleteAlertView comes into play:

- (void)deleteAlertView:(UIAlertView *)deleteButtonPressed
       didDismissWithButtonIndex:(NSInteger)buttonIndex {
    if (buttonIndex != [deleteButtonPressed cancelButtonIndex]) {
        [array removeObject:@"%@", deleteButtonPressed];
    }

The issue here is [array removeObject:@"%@", deleteButtonPressed];, I did the %@ so that this will automatically determine which object in the array was tapped, rather than manually putting in a new method and button for each UIImageView (I may have to end up doing that). I’m getting errors regarding “array” and “deleteButtonPressed” (use of undeclared identifier), I can’t for the life of me figure out what to put instead. I’m still learning the basics and how inheritance in this language works. Any help or advice would be great! I should probably post the whole view controller file to show the related inheritance:

 - (IBAction)grabImage {
    self.imgPicker = [[UIImagePickerController alloc] init];
    self.imgPicker.delegate = self;
    self.imgPicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
        _popover = [[UIPopoverController alloc] initWithContentViewController:imgPicker];
        [_popover presentPopoverFromRect:self.imageView.bounds inView:self.imageView permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
    } 

    else {
        [self presentModalViewController:imgPicker animated:YES];
    }
    [self.imgPicker resignFirstResponder];
}
// Sets the image in the UIImageView
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)img editingInfo:(NSDictionary *)editInfo {
    if (imageView.image == nil) {
        imageView.image = img;
        [picker dismissModalViewControllerAnimated:YES];
        [self.popover dismissPopoverAnimated:YES];
        return;

    }

    if (imageView2.image == nil) {
        imageView2.image = img;
        [picker dismissModalViewControllerAnimated:YES];
        [self.popover dismissPopoverAnimated:YES];
        return;
    }
    if (imageView3.image == nil) {
        imageView3.image = img;
        [picker dismissModalViewControllerAnimated:YES];
        [self.popover dismissPopoverAnimated:YES];
        return;
    }
}

- (void)viewWillAppear:(BOOL)animated
{

    self.user = [NSUserDefaults standardUserDefaults];

    NSMutableArray* array = [[self.user objectForKey:@"images"]mutableCopy];
    while(array == nil)
    {
        [self.user setObject:[NSMutableArray arrayWithObject:@""] forKey:@"images"];
        array = [[self.user objectForKey:@"images"]mutableCopy];
        NSLog(@"%@",@"attempting to create an array to store the images in");
    }

}

- (void)applicationDidEnterBackground:(UIApplication*)application {
    NSLog(@"Image on didenterbackground: %@", imageView);
    NSMutableArray* array = [NSMutableArray arrayWithObject:[NSData dataWithData:UIImagePNGRepresentation(imageView.image)]];

    [array addObject:[NSData dataWithData:UIImagePNGRepresentation(imageView2.image)]];
     [array addObject:[NSData dataWithData:UIImagePNGRepresentation(imageView3.image)]];

            [self.user setObject:array forKey:@"images"];
    [user synchronize];

            }

- (void)viewDidLoad
    {
        self.user = [NSUserDefaults standardUserDefaults];
        NSLog(@"It is %@", self.user);
        NSMutableArray* array = [[self.user objectForKey:@"images"]mutableCopy];
        imageView.image = [[UIImage alloc] initWithData:[array objectAtIndex:0]];
        imageView2.image = [[UIImage alloc] initWithData:[array objectAtIndex:1]];
        imageView3.image = [[UIImage alloc] initWithData:[array objectAtIndex:2]];


        UIApplication *app = [UIApplication sharedApplication];
        [[NSNotificationCenter defaultCenter] addObserver:self
                                                 selector:@selector(applicationDidEnterBackground:)
                                                     name:UIApplicationDidEnterBackgroundNotification
                                                   object:app];

        backToGalleryButton.hidden = YES;
        tapToDeleteLabel.hidden = YES;
        deleteButton1.hidden = YES;
        [super viewDidLoad];

    }

     - (IBAction)deleteButtonPressed:(id)sender {
    UIAlertView *deleteAlertView = [[UIAlertView alloc] initWithTitle:@"Delete"
                                                              message:@"Are you sure you want to delete this photo?"
                                                             delegate:self
                                                    cancelButtonTitle:@"Yes"
                                                    otherButtonTitles:@"No", nil];
    [deleteAlertView show];

}

- (void)deleteAlertView:(UIAlertView *)deleteButtonPressed
       didDismissWithButtonIndex:(NSInteger)buttonIndex {
    if (buttonIndex != [deleteButtonPressed cancelButtonIndex]) {
        [array removeObject:@"%@", deleteButtonPressed];
    }       

}
  • 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-01T06:39:11+00:00Added an answer on June 1, 2026 at 6:39 am

    The issue here is [array removeObject:@"%@", deleteButtonPressed];

    Yes, that is one of the issues (even ignoring the invalid syntax). The array does not contain your UIAlertView, it contains whatever objects [user objectForKey:@"images"] contains. Which seem like they should be NSData instances and which in any case are definitely not your UIAlertView instance(s).

    So in other words, you can’t pass the UIAlertView to the array in order to have the array magically work out what item the UIAlertView is supposed to correspond to. Instead what you should do is tag the UIAlertView with the index it corresponds to when you create it. You can do this like:

    UIAlertView *deleteAlertView = [[UIAlertView alloc] initWithTitle:@"Delete"
                                                                  message:@"Are you sure you want to delete this photo?"
                                                                 delegate:self
                                                        cancelButtonTitle:@"Yes"
                                                        otherButtonTitles:@"No", nil];
    int imageIndex = <figure out the index of the associated array element based upon 'sender'>;
    deleteAlertView.tag = imageIndex;
    

    …and then when the button is pressed, you do:

    [array removeObjectAtIndex:deleteButtonPressed.tag];
    

    And to fix up that “undeclared identifier” issue, you should declare array in your header and not in viewDidLoad. You want it to be a private instance variable, not a local variable.

    Also note that deleting an element from [[user objectForKey:@"images"] mutableCopy] will not automatically cause the corresponding element to be deleted from [user objectForKey:@"images"]. You need to write the modified array back to [NSUserDefaults standardUserDefaults] if you want the modification to actually persist.

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

Sidebar

Related Questions

If I need call this functions one after other, $('#art1').animate({'width':'1000px'},1000); $('#art2').animate({'width':'1000px'},1000); $('#art3').animate({'width':'1000px'},1000); I know
I need to call Ghostscript in one of our cgi to convert a PDF
I need to call some jQuery .load() function from flash. i Use this: import
I need to call a JS function with a C# parameter. This is inside
I need to call some PL/SQL procedures from my Java application. I can do
When do I actually need call this method Runtime.getRuntime().addShutdownHook() and when or why I
I need to call 2 functions onkeypress out of which first function is return
I need to call a function on a using jquery. This function needs to
I need to call this from the code behind if there is a certain
Need to call web method, from web service. but name of method is unknown

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.