0

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.

millhouse
  • 9,817
  • 4
  • 32
  • 40
user2962499
  • 486
  • 6
  • 10
  • Possible duplicate of [How can I debug 'unrecognized selector sent to instance' error](https://stackoverflow.com/questions/25853947/how-can-i-debug-unrecognized-selector-sent-to-instance-error) – Cœur Jul 08 '19 at 05:53

2 Answers2

2

Change your code to:

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

so that you're instantiating the correct class.

Wain
  • 118,658
  • 15
  • 128
  • 151
0

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
}
spaleja
  • 1,435
  • 15
  • 24