I know the unrecognized selector to instance message is very common but I can't seem to find what's causing it in my project. I'm trying to basically segue from one controller to another when a particular button is tapped. I define the segue in storyboard. The buttons however are not created in storyboard, the buttons are created programmatically in a view controller, which is then inherited by the controller that I'm trying to segue from. Here's the code of what I'm trying to do: First this is part of my ButtonViewController.m which has the button and it this controller that I'm inheriting
UIButton *EButton=[UIButton buttonWithType:UIButtonTypeCustom];
[EButton setFrame:CGRectMake(0, 450, 106, 60)];
[EButton setAutoresizingMask:UIViewAutoresizingFlexibleTopMargin];
[EButton setImage:[UIImage imageNamed:@"test1.png"] forState:UIControlStateNormal];
[EButton setImage:[UIImage imageNamed:@"test2.png"] forState:UIControlStateHighlighted];
[EButton setEnabled:YES];
[EButton addTarget:self action:@selector(EButtonPressed) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:EButton];
-(IBAction)EButtonPressed:(id)sender
{
[self performSegueWithIdentifier:@"WorldtoE" sender:self];
}
Now, I inherit this ButtonViewController.m in my WorldViewController. (Reason for this is, I need this button in different controller throughout my app and would prefer to just make changes once in case I need to). Now, the button is created perfect when I'm running the app, but as soon as I tap on it, I get this error: Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[WorldViewController EButtonPressed]: unrecognized selector sent to instance I even tried defining -(IBAction)EButtonPressed:(id)sender in my WorldViewController .h file and have also tried includingg the whole ibaction function in my .m file but I still get the same NSInvalidArgumentexception when I tap on the button. What am I doing wrong? And yes I have given the segue the same title in storyboard.
Replace line:
[EButton addTarget:self action:@selector(EButtonPressed) forControlEvents:UIControlEventTouchUpInside];
to:
[EButton addTarget:self action:@selector(EButtonPressed:) forControlEvents:UIControlEventTouchUpInside];