views:

49

answers:

1

I have a a xib with a toolbar and on that I have 2 buttons all made in IB. I can connect my outlets to the buttons but when I click them the method isn't triggered? Why is that?

In my header file I have this:

@property (nonatomic, retain) IBOutlet UIBarButtonItem *cancelEntry;
@property (nonatomic, retain) IBOutlet UIBarButtonItem *saveEntry;

-(IBAction) cancelEntry:(id) sender;
-(IBAction) saveEntry:(id) sender;

In my .m file I got this:

-(IBAction) cancelEntry:(id) sender {
 NSLog(@"cancel");
}

-(IBAction) saveEntry:(id) sender {
 NSLog(@"save");
}

All compiles as it should but no nothing in the log when clicking the buttons. What should I do to get it to work?

A: 

Sounds like you connected your outlets to the buttons, but didn't connect the buttons to the actions.

  1. Right click Cancel the UIBarButtonItem in Interface Builder.
  2. Hover over Selector, then drag the + that appears onto File's Owner.
  3. Connect it to cancelEntry:.
  4. Repeat for Save.

Instead of using (id) for your IBActions, you should probably use (UIBarButtonItem *). That'll prevent you from connecting a different object type to those IBActions.

Steven Fisher
Thank you tweha! Even though I solved it myself your answer is correct and what I didn't do.
swe_mattias