-2

I want to have a couple of buttons in my iOS app at the bottom of the screen and so used a UIToolBar and added a couple of Bar Button Items to it. But I realized that these BarButtonItems are not considered to be regular buttons. So I am not able to set actions on mouse up on these. Is there a way to set a function to be called when these buttons are clicked? If this is not possible through the storyboard, can I access it programmatically?

user220201
  • 4,514
  • 6
  • 49
  • 69
  • So it turns out I was wrong. I can in fact assign individual action functions to the BarButtonItems. I needed to start from the view level where all IBActions will be visible and then drag and assign the functions to the buttons. – user220201 Oct 03 '15 at 13:37

3 Answers3

1

Select the UIBarButtonItem, Control+Dragging at the implementation section in .m file. Create an IBAction. You may put a NSLog statement to check the user tap.

Abhinav
  • 37,684
  • 43
  • 191
  • 309
0

Create one outlet:

@property (weak, nonatomic) IBOutlet UIBarButtonItem *menuBarBtn;
  

In ViewDidLoad or somewhere you can add like this:

[_menuBarBtn setAction: @selector( revealToggle:)];
pkamb
  • 33,281
  • 23
  • 160
  • 191
Uma Madhavi
  • 4,851
  • 5
  • 38
  • 73
0

Do not make an IBAction from the bar button item object or the code will not run.

In the document outline, control+drag from the button INSIDE the bar button item container. The IBAction should run normally now.