Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Blakeasd

macrumors 6502a
Original poster
Dec 29, 2009
643
0
Hello,

I am having some issues using UIGestureTapRecognizer with an UIView.

Here is part of the code.

Code:
-(void)goToControlsView:(id)sender{
    
    NSLog(@"The album view has been tapped!");
    
    
}

-(void)applicationDidFinishLaunching:(UIApplication *)application{
    
    
    window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].applicationFrame];
    window.backgroundColor = [UIColor whiteColor];
    window.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
 
   
    albumView =  [[UIView alloc]initWithFrame:[[UIScreen mainScreen]bounds]];
    albumView.backgroundColor = [UIColor blueColor];
    [window addSubview:albumView];
    
    controlView = [[UIView alloc]initWithFrame:[[UIScreen mainScreen]bounds]];
    controlView.backgroundColor = [UIColor redColor];
    [window addSubview:controlView];
    controlView.hidden = YES;
    
    
    tapGestureRecognizer = [[UITapGestureRecognizer alloc]initWithTarget:albumView action:@selector(goToControlsView:)];
    tapGestureRecognizer.numberOfTapsRequired = 1;    
    [albumView addGestureRecognizer:tapGestureRecognizer];

    
    //any iOS code can go here
    //Do some iOS stuff method
    
    [window makeKeyAndVisible];

       
}

When I click on my UIView on get the "Unrecognized selector sent to instance" exception.

As far as I can tell, I'm not doing anything incorrectly. If anyone sees something that is incorrect with this code please share because I can't find it.

Code:
 goToControlsView:(id)sender
is also defined in the .h file, if that makes any difference.

thanks!
 
Last edited:
Hello,

I am having some issues using UIGestureTapRecognizer with an UIView.

Here is part of the code.

Code:
-(void)goToControlsView:(id)sender{
    
    NSLog(@"The album view has been tapped!");
    
    
}

-(void)applicationDidFinishLaunching:(UIApplication *)application{
    
    
    window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].applicationFrame];
    window.backgroundColor = [UIColor whiteColor];
    window.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
 
   
    albumView =  [[UIView alloc]initWithFrame:[[UIScreen mainScreen]bounds]];
    albumView.backgroundColor = [UIColor blueColor];
    [window addSubview:albumView];
    
    controlView = [[UIView alloc]initWithFrame:[[UIScreen mainScreen]bounds]];
    controlView.backgroundColor = [UIColor redColor];
    [window addSubview:controlView];
    controlView.hidden = YES;
    
    
    tapGestureRecognizer = [[UITapGestureRecognizer alloc]initWithTarget: albumView action:@selector(goToControlsView:)];
    tapGestureRecognizer.numberOfTapsRequired = 1;    
    [albumView addGestureRecognizer:tapGestureRecognizer];

    
    //any iOS code can go here
    //Do some iOS stuff method
    
    [window makeKeyAndVisible];

       
}

When I click on my UIView on get the "Unrecognized selector sent to instance" exception.

As far as I can tell, I'm not doing anything incorrectly. If anyone sees something that is incorrect with this code please share because I can't find it.

Code:
 goToControlsView:(id)sender
is also defined in the .h file, if that makes any difference.

thanks!

When you create your gesture recognizer, you're passing in a target of "albumView". The view controller in albumView is the one that has to implement the goToControlsView: selector.

If you want the gesture recognizer to call YOUR goToControlsView: method, pass in a target of "self" in your call to initWithTarget:action:
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.