NSInvalidArgumentException

Tearing my hair here. Read a lot of examples that describe how to get around this, but no one helped me get rid of this problem.

You have a simple button on a UIView related to IBAction.

The code is ...

Contact.h

#import <UIKit/UIKit.h>

@interface Contact : UIViewController {
}

-(IBAction)buttonPressed:(id)sender;

@end

Contact.m

#import "Contact.h"

@implementation Contact

- (IBAction)buttonPressed:(id)sender  
{
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Button Pressed" message:@"You pressed the button" delegate:nil cancelButtonTitle:@"Yep, I did." otherButtonTitles:nil];
    [alert show];
    [alert release];
}

Constantly receiving this error message:

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

Touch Up Inside is associated with the file owner using buttonPressed.

We downloaded another sample code, and they work fine. My project and nib are set up the same way with another sample code.

I don’t know where you can even try and debug this.

Can anybody help?

+3
source share
4 answers

. , ViewController TabBarController , NIB , .

+5

Builder , . " ", "" "" ( "i" ) .

+1

, ? Contact.m @implementation, , @interface,

Contact.m:

#import "Contact.h"

@implementation Contact

- (IBAction)buttonPressed:(id)sender
{
    NSLog(@"buttonPressed");
}

@end
0

, , UIView ,

It makes me think that you are not setting up the situation correctly. If this is a nib application file and it contains nothing but UIViewFile Owner will be your application delegate, regardless of whether you set the file owner type to IB.

Try the following:

  • Create an instance Contactin the nib file: drag the object UIViewControllerand set its class to Contact.

  • Connect the view and button to your instance Contact.

  • Let us know if this works :)

0
source

Source: https://habr.com/ru/post/1716508/


All Articles