views:

746

answers:

2

I dropped a UINavigationBar onto the XIB form. Then I dropped a UIButton on the form (not on the NavigationBar). I changed the type to InfoLight (so that it looks like an Info symbol).

I then dragged the UIButton onto the UINavigationBar and set it to be the right button. It magically changes the type from UIButton to UIButtonBarItem as a result of the drag.

Why didn't I just dragged the UIButton onto the UINavigationBar to begin with? Because, once the button is there, Interface Builder won't let you change the type to InfoLight for whatever reason.

The in the adjoining .h file, I created a declaration for the IBAction

- (IBAction) btnInfoClick;

Then in the .m file, I wrote the implementation:

- (IBAction) btnInfoClick {
    // kick off the about screen
    // code follows
}

How do I now hook up the button on the navigation bar to my btnInfoClick function?

Or am I going about it the wrong way to begin with?

I should note that if I simply drag a button from the Library straight onto the navigation bar, I can click on the File Owner icon, and then drag the btnInfoClick IBAction onto the button. In this case, the click event fires fine.

However, in the scenario where I first drag the button elsewhere and then onto the navigation bar, the event never fires. Not sure what I am doing wrong.

A: 

Open up IB, select the UIBarButtonItem and in the Inspector, go to the Connections tab.

Drag from the dot at the right of selector to your AppDelegate/File's Owner (the one where the action has been defined) and select the action.

I suppose you've already tried that, but just in case. When the action does not show up, try adjusting your action definition to be something like:

- (IBAction)btnInfoClick:(id)sender;

and try the process again. I know you don't really have to specify the sender (at least programmatically, the way I always use) but I had the same problem and after adding the sender param it worked correctly.

Good luck and let me know whether this works!

JoostK
A: 

I think, it's a bug in IB. But I found a workaround here. Reposting for posterity:

  1. Create a button in the view (not the navigation bar!)
  2. Set this button to be Info Light
  3. Set the action for this button to be Touch Inside Up
  4. Move the button to the navigation bar
AngryHacker