AlanL
AlanL

Reputation: 636

UIBarButtonItem created in Interface Builder not working - confused

I am trying to tidy up my UI by consolidating various things in a Tool Bar, and am utterly confused. I am using Interface Builder rather than constructing the controls programmatically, because my UI is fairly simple and not particularly dynamic.

What I did did so far:

  1. Added an empty tool bar.
  2. Dragged two previously existing and working buttons onto the tool bar. They changed their class from UIButton to UIBarButtonItem, and the inspector now shows them as having no Sent Actions or Referencing Outlet, but the the previous action & outlet in the View Controller - responding to taps, setting the label of the button - still work.
  3. Created a new Button directly in the tool bar. Wired up its action & outlet by ctrl-drag in the normal way. The inspector shows the Action and Outlet for this button as connected, which is nice, but sadly neither of them works. Clicking the button does not invoke the action; setting the label of the button does not cause anything to happen on the screen, even after I tried prodding the tool bar with a setNeedsDisplay.

I'm not sure what to try next. Googling has shown me that I'm not the only person to find using UIToolBar via Interface Bulder difficult and confusing, but I haven't found a solution to my exact problem.

I don't particularly want to resort to creating my entire GUI programmatically just to tidy up a few buttons. Creating all the controls in Interface Builder outside the tool bar, getting them wired up and working, then moving them into the tool bar would presumably also work - but it would be a kludge, and would leave me still none the wiser if anything went wrong later.

Upvotes: 2

Views: 1077

Answers (2)

Add080bbA
Add080bbA

Reputation: 1876

i had a similar issue. Did you created an extra UITapGestureRecognizer for root view ? Maybe for something like > When elsewhere than UITextView clicked, resignFirstResponder for all UITextViews !

In my case, on 7.1, that extra UITapGestureRecognizer prevented transfer of event to IBAction of UIBarButtonItem which is inside an UIToolBar. IBAction was made on Storyboard by Ctrl+Drag. on 8.1 it was working. Not on 7.1

Read some suggestions to create an extra UIView and putting all visual elements into that extra UIView except UIToolBar

Upvotes: 0

John
John

Reputation: 2694

Should you try using UIBarButtonItem instead of UIButton? It works for me.

Upvotes: 2

Related Questions