Resolved Unrecognized selector sent to instance

Discussion in 'iOS Programming' started by Blakeasd, Jul 2, 2013.

  1. Blakeasd, Jul 2, 2013
    Last edited: Jul 2, 2013

    Blakeasd macrumors 6502a

    Joined:
    Dec 29, 2009
    #1
    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!
     
  2. Duncan C macrumors 6502a

    Duncan C

    Joined:
    Jan 21, 2008
    Location:
    Northern Virginia
    #2
    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:
     
  3. Blakeasd thread starter macrumors 6502a

    Joined:
    Dec 29, 2009
    #3
    Can't believe I didn't catch that stupid mistake :eek: . Thank You!
     

Share This Page