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

  • Home
  • SEARCH
  • 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 3285652
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T20:17:27+00:00 2026-05-17T20:17:27+00:00

New to iPhone dev. I have a view which contains a UIScrollView which contains

  • 0

New to iPhone dev. I have a view which contains a UIScrollView which contains a UIImageView. I added a (double) tap gesture recognizer on the image view which makes an alert box open. For some reason, and I’m sure I’m just retarded, it opens 3 times.

Here’s my code:

- (void)viewDidLoad {

    scrollView.delegate = self;

    UIImage* image = imageView.image;
    imageView.bounds = CGRectMake(0, 0, image.size.width, image.size.height);
    scrollView.contentSize = image.size;

    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapGesture:)];
    tapGesture.numberOfTapsRequired = 2;
    [imageView addGestureRecognizer:tapGesture];
    [tapGesture release];

    NSLog(@"LOADED");

    [super viewDidLoad];
}

-(IBAction) handleTapGesture:(UIGestureRecognizer *) sender {
    CGPoint tapPoint = [sender locationInView:imageView];
    int tapX = (int) tapPoint.x;
    int tapY = (int) tapPoint.y;
    NSLog(@"TAPPED X:%d Y:%d", tapX, tapY);
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Hello" message:@"How are you?" delegate:nil cancelButtonTitle:@"I'm awesome." otherButtonTitles:nil];
    [alert show];
    [alert release];
}

I just started iPhone dev a few days ago. This problem kind of reminds me of event bubbling issues I’ve dealt with in javascript. Any ideas?

  • 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-17T20:17:27+00:00Added an answer on May 17, 2026 at 8:17 pm

    Not sure what the exact reason is but the UIAlertView is somehow causing the gesture to fire again. A workaround is to execute the showing outside the gesture handler using performSelector:

    -(void) handleTapGesture:(UIGestureRecognizer *) sender {
        CGPoint tapPoint = [sender locationInView:imageView];
        int tapX = (int) tapPoint.x;
        int tapY = (int) tapPoint.y;
        NSLog(@"TAPPED X:%d Y:%d", tapX, tapY);
        [self performSelector:@selector(showMessage) withObject:nil afterDelay:0.0];
    }
    
    - (void)showMessage
    {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Hello" message:@"How are you?" delegate:nil cancelButtonTitle:@"I'm awesome." otherButtonTitles:nil];
        [alert show];
        [alert release];
    }
    

    Edit:
    The gesture recognizer goes through different states in the gesture (Began, Changed, etc) and it calls the handler method each time the state changes. So a better and probably correct solution is to check the state property of the gesture recognizer at the top of the handler:

    -(void) handleTapGesture:(UIGestureRecognizer *) sender {
        if (sender.state != UIGestureRecognizerStateEnded)  // <---
            return;                                         // <---
    
        CGPoint tapPoint = [sender locationInView:imageView];
        int tapX = (int) tapPoint.x;
        int tapY = (int) tapPoint.y;
        NSLog(@"TAPPED X:%d Y:%d", tapX, tapY);
    
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Hello" message:@"How are you?" delegate:nil cancelButtonTitle:@"I'm awesome." otherButtonTitles:nil];
        [alert show];
        [alert release];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am pretty new to this iPhone dev thing but so far I have
I'm new to iPhone dev and need some help with adding subViews. I have
I am new to mac development (I've been into iPhone dev so have a
I am new in iPhone world, I have register to iPhone Dev program today
I'm new to iPhone dev and Obj-C and I have several problems with ScrollView/ImageView
I'm pretty new to iPhone dev, so any help is appreciated. I am creating
I am new to iphone dev and I'm trying to create a bookmark in
Fairly new to iPhone dev. My app uses Core Data, and at one point
I've added Facebook Connect to my new iPhone application. Everything perfect, no problem. In
How do i put a swipe gesture in the new iPhone SDK? I'm trying

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.