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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T14:43:37+00:00 2026-06-01T14:43:37+00:00

So I have an app that behaves like a photo gallery and I’m implementing

  • 0

So I have an app that behaves like a photo gallery and I’m implementing the ability for the user to delete the images. Here is the setup: I have 9 UIImageViews, imageView, imageView2, etc. I also have an “Edit” button, and a tapGesture action method. I dragged a Tap Gesture Recognizer over onto my view in IB, and attached it to each one of the UIImageViews. I also attached the tapGesture action method to each of the UIImageViews. Ideally, I would like the method to only become active when the “Edit” button is pressed. When the user taps Edit, then taps on the picture they want to delete, I would like a UIAlertView to appear, asking if they are sure they want to delete it. Here is the code I’m using:

- (IBAction)editButtonPressed:(id)sender {
    editButton.hidden = YES;
    backToGalleryButton.hidden = NO;
    tapToDeleteLabel.hidden = NO;
}

- (IBAction)tapGesture:(UITapGestureRecognizer*)gesture
{

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

    if (buttonIndex != [alertView cancelButtonIndex]) {

        UIImageView *view = [self.UIImageView];
        if (view) {
            [self.array removeObject:view];
        }


        CGPoint tapLocation = [gesture locationInView: self.view];
        for (UIImageView *imageView in self.view.subviews) {
            if (CGRectContainsPoint(self.UIImageView.frame, tapLocation)) {
                ((UIImageView *)[self.view]).image =nil;
 }

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

This code is obviously riddled with errors:
“Use of undeclared identifier button index” on this line: if (buttonIndex != [alertView cancelButtonIndex])

“Property UIImageView not found on object of type PhotoViewController” on this line UIImageView *view = [self.UIImageView];

And “Expected identifier” on this line ((UIImageView *)[self.view]).image =nil;

I’m very new to programming, and I’m surprised that I even made it this far. So, I’m just trying to figure out how I need to edit my code so that the errors go away, and that it can be used whenever one of the 9 image views is tapped, and also so that this method only fires when the Edit button is pushed first. I was using tags earlier, and it worked great, but I save the images via NSData, so I can’t use tags anymore. Any help is much appreciated, thanks!

  • 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-01T14:43:39+00:00Added an answer on June 1, 2026 at 2:43 pm

    First, you don’t want to attach the tap gesture to the image views. Also, if you are going to have more than 9 images, you may want a scroll view, or handle scrolling separately. First, remove that gesture recognizer and all its connections.

    Next, determine what type of view you will use as your gallery canvas. A simple View, or a ScrollView, or whatever… it doesn’t really matter right now, just to get it working. You want to ctrl-drag that view into your interface definition, so it drops an IBOutlet for the view (that way you can reference it in code).

    You will place your ImageViews onto the view I just mentioned.

    You can have an internal flag for the gesture recognizer, but it also has a property that use can enable/disable it whenever you want. Thus, you can have it active/inactive fairly easily.

    All you want to do is drop a single tap-gesture-recognizer onto your controller, and connect it to the implementation section of the controller. It will generate a stub for handling the recognizer. It will interpret taps “generally” for the controller, and call your code whenever a tap is made on the view.

    Some more code…

    Creates a frame for the “new” image in the scroll view.

    - (CGRect)frameForData:(MyData*)data atIndex:(NSUInteger)idx
    {
        CGPoint topLeft;
        int row = idx / 4;
        int col = idx % 4;
        topLeft.x = (col+1)*HORIZ_SPACING + THUMBNAIL_WIDTH * (col);
        topLeft.y = (row+1)*VERT_SPACING + THUMBNAIL_HEIGHT * (row);
        return CGRectMake(topLeft.x, topLeft.y, THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT);
    }
    

    Creates an image view for each piece of metadata, and a small border.

    - (UIImageView*)createImageViewFor:(MetaData*)metadata
    {
        UIImageView *imageView = [[UIImageView alloc] initWithImage:metadata.lastImage];
        imageView.frame = CGRectMake(0, 0, THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT);;
        imageView.layer.borderColor = [[UIColor blackColor] CGColor];
        imageView.layer.borderWidth = 2.0;
        imageView.userInteractionEnabled = YES;
        return imageView;
    }
    

    This is where the views are created and added to the parent…

        imageView = [self createImageViewFor:metadata];
        //[data.imageView sizeToFit];
    
        // Make sure the scrollView contentSize represents the data
        CGRect lastFrame = [self frameForData:data atIndex:self.data.count-1];
        CGFloat newHeight = lastFrame.origin.y + lastFrame.size.height;
        if (self.bookshelfScrollView.contentSize.height < newHeight) {
            CGSize newSize = self.bookshelfScrollView.contentSize;
            newSize.height = newHeight;
            self.bookshelfScrollView.contentSize = newSize;
        }
        [self.bookshelfScrollView addSubview:data.imageView];
    

    So, you just create each frame, add them to the view, and the only thing you have to do is enable user interaction on them, because otherwise the scroll view does not allow the gesture through.

    OK… Looking at the code you posted… since you didn’t say what was wrong with it… hard to say… The below is your code… My comments are, well, Comments…

    - (IBAction)editButtonPressed:(id)sender {
        editButton.hidden = YES;
        backToGalleryButton.hidden = NO;
        tapToDeleteLabel.hidden = NO;
    }
    - (IBAction)tapGesture:(UITapGestureRecognizer*)gesture
    {
        // I don't think I'd do this here, but it shouldn't cause "problems."
        UIAlertView *deleteAlertView = [[UIAlertView alloc] initWithTitle:@"Delete"
                                                                  message:@"Are you sure you want to delete this photo?"
                                                                 delegate:self
                                                        cancelButtonTitle:@"No"
                                                        otherButtonTitles:@"Yes", nil];
        [deleteAlertView show];
    
        // In your controller, you have the main view, which is the view
        // on which you added your UIViews.  You need that view.  Add it as an IBOutlet
        // You should know how to do that...  ctrl-drag to the class INTERFACE source.
        // Assuming you name it "galleryView"
    
        // Take the tap location from the gesture, and make sure it is in the
        // coordinate space of the view.  Loop through all the imageViews and
        // find the one that contains the point where the finger was taped.
        // Then, "remove" that one from its superview...
        CGPoint tapLocation = [gesture locationInView: self.galleryView];
        for (UIImageView *imageView in self.galleryView.subviews) {
            if (CGRectContainsPoint(imageView.frame, tapLocation)) {
                [imageView removeFromSuperview];
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an app that behaves somewhat like a photo gallery. They choose an
I'm working on an app that behaves like a photo gallery, and I'm implementing
I'd like to add a piece of functionality to an app that behaves similar
I'm currently developing an app that behaves like the Messages.app. The MasterViewController is the
I have an application that behaves oddly, and just to verify, I'd like to
have an app that finds your GPS location successfully, but I need to be
Have an app that has listings - think classified ads - and each listing
I have an app that needs to open a new window (in the same
I have an app that executes commands on a Linux server via SSH just
I have a app that I'm deploying to a development server using Capistrano. I'd

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.