简体   繁体   中英

Why am I seeing the following exception within my application?

I'm creating an iPhone application. I have two view controllers (the main one and an about window). In the about view controller i have a UIButton which is linking to a IBAction in the view controller.

I'm getting:

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'

Heres the code:

//
//  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

I'm 100% sure that everything is linked up correctly in xCode and Interface Builder

Any help is greatly appreciated

Thanks. Daniel

UPDATE: I found out just now that its trying to point to a different class.. But its correct in IB???

You should check where you actually create this instance of AboutViewController. Setting the class for "File's Owner" just tells IB what class to expect . But it may be that the actual object loading this nib is not an AboutViewController.

BTW, "editing" error messages to hide some secret is a good way to obscure the actual bug and make it harder for other people to help. :)

The error message says aboutViewController , but in your code it is named AboutViewController . Make sure the case matches, also in the Interface Builder properties.

If you have it setup correctly then its a "Thing Inside(TM)".

Delete the button. Create a new one and set it up again.

Make sure to exit and reload in Interface Builder.

Try:

- (IBAction)goToMain2:(id)sender;

and

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

Clearly you haven't linked it up correctly, or you would not be getting the exception.

I wouldn't mind betting that the error message looks more like this:

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

The reason I think that is that IBAction s are usually declared thus:

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

If that's not the problem, you need to run the application in the debugger with break on exception set. You can then check if the object to which the action is being sent really is what you think it is.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM