2
votes

In my iPhone application I have such code:

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.title = @"Instruction Controller";
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(menuButtonClicked)];   
}   


#pragma mark private methodes

-(void) menuButtonClicked{
    NSLog(@"menuButtonClicked");
}

But when I click on this button it raise an exeption: "Unrecognized selector sent to instance". How cam I resolve this issue?

UPDATE

2013-05-23 12:21:33.182 CICDP[3091:11603] -[__NSCFString menuButtonClicked]: unrecognized selector sent to instance 0x8128eb0 2013-05-23 12:21:33.188 CICDP[3091:11603] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString menuButtonClicked]: unrecognized selector sent to instance 0x8128eb0'

3
What was the selector?Mike Pollard
@selector(menuButtonClicked) - you can see it in my postrevolutionkpi
But what dos the error say in the console?Mike Pollard
can you post the complete stacktrace? what instance, what selector were detectedgeo
I have provide you with itrevolutionkpi

3 Answers

5
votes

It looks like your controller class (the target of the button action) is being released before the button fires. The button is likely retained by its superview.

You need to do something to keep the controller class alive (some other instance needs to hold a strong reference to it) for the whole time the button is on display.

0
votes

I have got the same issue but it wasn't a reference issue. The log 'Unknown class MyViewController in Interface Builder file.' helps me a lot.

I have solved this issue with the answer : Xcode 6 Strange Bug: Unknown class in Interface Builder file

To resolve this issue, be sure the module associated to your view is correctly set :

If you see Module None, there is the issue

enter image description here

Go on Module and just tap enter to see this :

enter image description here

-3
votes

You need to add a : to the selector and change the method

- (void)viewDidLoad

{

    [super viewDidLoad];

    self.title = @"Instruction Controller";

    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] 
        initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self 
        action:@selector(menuButtonClicked:)];   

}

-(void) menuButtonClicked:(id)sender {
    NSLog(@"menuButtonClicked");
}