为什么我在应用程序中看到以下异常?

时间:2010-08-05 11:47:01

标签: iphone objective-c

我正在创建一个iPhone应用程序。我有两个视图控制器(主要的一个和一个关于窗口)。 在about视图控制器中,我有一个UIButton,它链接到视图控制器中的IBAction。

我得到了:

2010-08-05 21:40:05.741 appname[9151:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[aboutViewController gotoMain2]: unrecognized selector sent to instance 0x5c09950'

下面是代码:

//
//  aboutAboutViewController.h
//
//  Created by **** on 5/08/10.
//  Copyright 2010 ***. All rights reserved.
//

#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>

@interface AboutViewController : UIViewController {

}
- (IBAction)gotoMain2;
@end

And the .m file:

//
//  AboutViewController.m
//
//  Created by **** on 5/08/10.
//  Copyright 2010 ****. All rights reserved.
//

#import "AboutViewController.h"

@implementation AboutViewController
- (IBAction)gotoMain2 { 
 [self dismissModalViewControllerAnimated:TRUE];
}
@end

我100%确定在xCode和Interface Builder中正确链接了所有内容

非常感谢任何帮助

感谢。 丹尼尔

更新:我刚刚发现它试图指向另一个类......但它在IB中是正确的???

5 个答案:

答案 0 :(得分:2)

您应该检查实际创建此AboutViewController实例的位置。设置“文件所有者”的类只是告诉IB 期望的类。但可能是加载此nib的实际对象不是AboutViewController。

BTW,“编辑”错误消息隐藏一些秘密是掩盖实际错误并让其他人更难帮助的好方法。 :)

答案 1 :(得分:0)

错误消息显示aboutViewController,但在您的代码中,它名为AboutViewController。确保案例匹配,也在Interface Builder属性中。

答案 2 :(得分:0)

如果您正确设置了它,那就是“Thing Inside(TM)”。

删除按钮。创建一个新的并重新设置。

确保在Interface Builder中退出并重新加载。

答案 3 :(得分:0)

尝试:

- (IBAction)goToMain2:(id)sender;

- (IBAction)goToMain2:(id)sender {
    [self dismissModalViewControllerAnimated:YES];
}

答案 4 :(得分:0)

显然,你没有正确地链接它,或者你不会得到例外。

我不介意打赌错误信息看起来更像是这样:

-[AboutViewController gotoMain2:]: unrecognized selector sent to instance 0x5c09950
                               ^^ colon here

我认为这是因为IBAction s通常是这样宣布的:

-(IBAction) doAnAction: (id) sender;
                      ^^^^^^^^^^^^^ actions take a parameter which is the object that sends them..

如果这不是问题,则需要在调试器中运行应用程序,并在异常集上中断。然后,您可以检查发送操作的对象是否真的是您认为的。

相关问题