Reputation: 1535
Am tearing my hair out here. Have read many examples which describe how to get around this but none have helped me get rid of the problem.
Have a simple button on a UIView linked to an IBAction.
Code is this...
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 linked to the file's owner using buttonPressed.
Have downloaded other example code and they work fine. My project and nib are set up identically to the other example code.
Haven't got a clue where to even start to try and debug this.
Anyone help?
Upvotes: 3
Views: 4768
Reputation: 2151
I had this exact same problem. It's because your ViewController was under a TabBarController and in the View Controller under it, you set the NIB Name to Contact but did not set the Class to Contact in the identity pane.
Upvotes: 5
Reputation: 119124
just created a brand new project with nothing inside it other than a UIView and a button and it is still happening
This makes me think that you are not quite setting things up properly. If this is the application nib file, and it contains nothing but a UIView
, then the File's Owner will be your application delegate, regardless of what you set the type of file's owner to be in IB.
Try the following:
Create an instance of Contact
in your nib file: drag in a UIViewController
object, and set its class to Contact
.
Wire up the view and the button up to your Contact
instance.
Let us know if that works :)
Upvotes: 0
Reputation: 18776
In Interface Builder, you need to tell it what class File's Owner is. Click the "File's Owner" icon, go to the Identity pane in the Inspector (the 'i' icon at the end) and change the Class to Contact.
Upvotes: 1
Reputation: 4551
Are you sure you pasted the right code? Your Contact.m should contain a @implementation
block containing the implementation, not a @interface
block containing the definitions
Contact.m:
#import "Contact.h"
@implementation Contact
- (IBAction)buttonPressed:(id)sender
{
NSLog(@"buttonPressed");
}
@end
Upvotes: 0