Search code examples
iphoneobjective-cuibarbuttonitemibactioniboutlet

I can't initialize my UIBarButtonItem?


I'm facing the following issue. I have a view with a UINavigationBar (not NavController) added with XIB, and on this bar a ButtonBarItem.

Now I want my button to print "Hello" in the console. This is my current code :

.h

@property (nonatomic, retain) IBOutlet UIBarButtonItem *boutonInfos;
- (IBAction)versVueInfos : (UIBarButtonItem *)sender;

.m

@synthesize boutonInfos;
[...]
- (IBAction) versVueInfos : (UIBarButtonItem *) sender { NSLog(@"Hello"); }

But if I try to connect the button to the action versvueInfos, my app stops running when I click on the button with this error :

-[UIViewController versVueInfos:]: unrecognized selector sent to instance 0x60117f0 2012-05-19 13:54:36.512 EC[1405:207] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIViewController versVueInfos:]: unrecognized selector sent to instance 0x60117f0'

When I try to connect the button to the outlet boutonInfos, same problem but my app even doesn't run :

2012-05-19 13:58:17.948 EC[1441:207] * Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key boutonInfos.'

So what am I doing wrong ? Sorry if this is very noobish, but I'm still a beginner in Obj-C/iPhone programming.


Solution

  • check the class of the xib file in interface builder.If it is of your viewcontroller class then it might work.... its a guess because in the error log its still showing uiviewcontroller instead of your viewcontroller class name .check the files owner class in interface builder