jdog
jdog

Reputation: 10759

Unrecognized selector sent to instance

Anyone know why I am getting this error?

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[CustomRaisedTabViewController cancel:]: unrecognized selector sent to instance 0x4d321e0'

This is the code where it is failing. This is in my CustomTabViewController. The error is happening when I click my "Cancel" button.

-(IBAction)showPostModalViewController {

PostActionModalViewController *addController = [[PostActionModalViewController alloc] 
                                                initWithNibName:@"PostActionModalView" bundle:nil];

// Configure the PostAddViewController. In this case, it reports any
// changes to a custom delegate object.

addController.delegate = self;



// Create the navigation controller and present it modally.

UINavigationController *navigationController = [[UINavigationController alloc]
                                                initWithRootViewController:addController];

[self presentModalViewController:navigationController animated:YES];

UIBarButtonItem *cancelButton =
[[UIBarButtonItem alloc] initWithTitle: @"Cancel"
                                 style: UIBarButtonItemStylePlain
                                target: self
                                action: @selector(cancel:)];
addController.navigationItem.rightBarButtonItem = cancelButton;
[cancelButton release];


//[self presentModalViewController:addController animated:true];
[navigationController release];

[addController release];
}

-(IBAction)cancel {
    [self.parentViewController dismissModalViewControllerAnimated:YES];
}

Upvotes: 3

Views: 19913

Answers (3)

scriba
scriba

Reputation: 97

you have to modify the cancel method signature in

-(IBAction)cancel:(id)sender
 { 
   [self.parentViewController dismissModalViewControllerAnimated:YES]; 
 }

when you added the action to your cancelButton (during initialization) you specified the "cancel:" selector, this means that it will be called a method having one parameter (the sender button)

Upvotes: 0

Kiran
Kiran

Reputation: 345

action: @selector(cancel:) 

For the action selector which takes parameter! cancel: that means which will take another parameter.

change your method to

-(IBAction)cancel:(id)sender{
// Do wat you want
}

or

-(IBAction)cancel:(UIButton *)btnSender{
/// Do what you want
}

Upvotes: 1

jer
jer

Reputation: 20236

Because the cancel: method is not cancel which is what you've defined.

Change your cancel action to look like this:

- (IBAction)cancel:(id)sender {
    ...
}

Upvotes: 9

Related Questions