help with unrecognized selector sent to instance

I'm sorry to have to ask but can someone help me with this.

I have been through the discussions of similar problem but cant seem to see what I'm doing wrong.

Using xcode 6.4 on osx 10.10 target is iOS 5.1 iPad

App works ok but not the tap on.


Message

reason: '-[UIImageView mousetap:]: unrecognized selector


Code snippet

// mouse

// Created by major on 19/10/2017.

// Copyright (c) 2017 MST. All rights reserved.


#import "RunViewController.h"


@interface RunViewController ()

@end


@implementation RunViewController

float animationStopDelay;

UIImageView *animationMouseSouthImageView;


-(void)mousetap:(id)sender {

NSLog(@"mousetap");

[self playsound:3];

int direction = (int)arc4random()%7;

NSLog(@"direction=%i",direction);

if ([mouseDirection isEqualToString:@"S"]){

[animationMouseSouthImageView stopAnimating];

[self.view sendSubviewToBack:animationMouseSouthImageView];

}

}


- (void)initmouse{

NSArray *mouseSouthImageNames = @[@"mouse-S-1.jpeg",@"mouse-S-2.jpeg",@"mouse-S-3.jpeg"];


NSMutableArray *mouseSouthImages = [[NSMutableArray alloc] init];

for (int i=0; i<mouseSouthImageNames.count; i++) {

[mouseSouthImages addObject:[UIImage imageNamed:[mouseSouthImageNames objectAtIndex:i]]];

}


animationMouseSouthImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,128,128)];

animationMouseSouthImageView.animationImages = mouseSouthImages;

animationMouseSouthImageView.animationDuration = 1;

animationMouseSouthImageView.animationRepeatCount = 1;

UITapGestureRecognizer *mousetapSouth = [[UITapGestureRecognizer alloc] initWithTarget:animationMouseSouthImageView action:@selector(mousetap:)];

mousetapSouth.numberOfTapsRequired = 1;

[animationMouseSouthImageView setUserInteractionEnabled:YES];

[animationMouseSouthImageView addGestureRecognizer:mousetapSouth];

CGRect screenBound = [[UIScreen mainScreen] bounds];

CGRect frame = animationMouseSouthImageView.frame;

frame.origin.x = mousex;

frame.origin.y = mousey;

frame.size.height = 128;

frame.size.width = 128;

animationMouseSouthImageView.frame = frame;


[self.view addSubview:animationMouseSouthImageView];


}

- (void)viewDidLoad {

NSLog(@"EnteredViewDidLoad");

[super viewDidLoad];

[self initmouse];

NSLog(@"InitDoneNowRunIt");

[animationMouseSouthImageView startAnimating];


// use performselector to test tap routine

[animationMouseSouthImageView performSelectorOnMainThread:@selector(mousetap:) withObject:nil waitUntilDone:true];

// Fails here

}

@end

You have added a gestureRecognizer for mousetapSouth:


addGestureRecognizer:mousetapSouth


But seems you have not added one for mousetap. You have just alloced it.

Accepted Answer

This is your offending line:


UITapGestureRecognizer *mousetapSouth = [[UITapGestureRecognizer alloc] initWithTarget:animationMouseSouthImageView action:@selector(mousetap:)];


You specified a target of animationMouseSouthImageView instead of self. The image doesn't define mousetap, self does.

help with unrecognized selector sent to instance
 
 
Q