user2962499
user2962499

Reputation: 496

unrecognized selector sent to instance

I am trying to get a pop up menu on iPhone. The main app is using storyboard, but the pop up is a separate xib file that I load:

menu = [[UIViewController alloc] initWithNibName:@"SimpleMenuController" bundle:nil];
[self.view addSubview:menu.view];

and I slide it in and out with animation when pressing a button.

that works fine, but I get a problem when I try to press a button inside that pop up menu

I get the following error:

Terminating app due to uncaught exception 'NSInvalidArgumentException', 
 reason: '-[UIViewController PressCategory:]: 
 unrecognized selector sent to instance 0x8d3c040'

I have connected the button to PressCategory function I have connected the view to the file owner.

What I have noticed is that my ViewController is called SimpleMenuViewController, that is where the PressCategory function is, so of course it will not find the selector. But I don't know what I am doing wrong in connecting in the xib file.

Upvotes: 0

Views: 139

Answers (2)

spaleja
spaleja

Reputation: 1435

Do you have PressCategory function in your SimpleMenuViewController? If yes, then check weather its parameterized or not.

Declare function in .h file like this:

-(IBAction)PressCategory:(UIButton *)sender;

Define it in .m file like this:

-(IBAction)PressCategory:(UIButton *)sender {
     // write your code here
}

Upvotes: 0

Wain
Wain

Reputation: 119041

Change your code to:

menu = [[SimpleMenuViewController alloc] initWithNibName:@"SimpleMenuController" bundle:nil];

so that you're instantiating the correct class.

Upvotes: 2

Related Questions