iphone - NSInvalidArgumentException

标签 iphone cocoa-touch

我在这里撕扯我的头发。已阅读许多描述如何解决此问题的示例,但没有一个可以帮助我解决该问题。

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

代码是这样的...

联系方式.h

#import <UIKit/UIKit.h>

@interface Contact : UIViewController {
}

-(IBAction)buttonPressed:(id)sender;

@end

联系方式.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];
}

不断收到此错误消息:

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

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

已经下载了其他示例代码,它们工作正常。我的项目和 Nib 的设置与其他示例代码相同。

不知道从哪里开始尝试调试它。

有人帮忙吗?

最佳答案

我也遇到了同样的问题。这是因为您的 ViewController 位于 TabBarController 下,并且在其下的 View Controller 中,您将 NIB Name 设置为 Contact,但没有在身份 Pane 中将 Class 设置为 Contact。

关于iphone - NSInvalidArgumentException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1358579/

相关文章:

iphone - 单个上下文,但在不同上下文中的对象之间为 "Illegal attempt to establish a relationship ' xyz'

ios - 云包 "Your request contains more than the maximum number of items in a single request (400)"

iphone - 花栗鼠碰撞检测

iphone - 如何从 int 转换为无符号短整型 - iPhone

iphone - 对待 SpriteKit Swift 中的每个节点

iphone - 自定义键盘 - 将数字放在字符顶部

objective-c - 为什么我似乎必须在 iOS 应用程序委托(delegate)中强制转换 window.rootViewController?

ios - 什么时候应该使用 __bridge 与 CFBridgingRelease/CFBridgingRetain?

iphone - 在 iOS 3.0 中测试 iPhone 应用程序

iphone - 在 XCode 上正确调试 iPhone 应用程序