NSInvalidArgumentException

jos*_*ney 3 iphone cocoa-touch

我在这里撕扯我的头发.已经阅读了许多描述如何解决这个问题的例子,但没有一个帮助我摆脱这个问题.

在UIView上有一个简单的按钮链接到IBAction.

代码就是这个......

Contact.h

#import <UIKit/UIKit.h>

@interface Contact : UIViewController {
}

-(IBAction)buttonPressed:(id)sender;

@end
Run Code Online (Sandbox Code Playgroud)

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];
}
Run Code Online (Sandbox Code Playgroud)

不断收到此错误消息:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[UIViewController buttonPressed:]: unrecognized selector sent to instance 0xd1d5f0'
Run Code Online (Sandbox Code Playgroud)

Touch Up Inside使用buttonPressed链接到文件的所有者.

已下载其他示例代码,它们工作正常.我的项目和笔尖的设置与其他示例代码完全相同.

还没有找到哪里开始尝试调试它的线索.

有人帮吗?

ber*_*dom 5

我有同样的问题.这是因为您的ViewController位于TabBarController下,在其下的View Controller中,您将NIB Name设置为Contact,但未在Identity窗格中将Class设置为Contact.