Jesse Durham
Jesse Durham

Reputation: 285

Adding functionality to UIToolbar Items in IB

This is a simple question, but IB makes things so difficult sometimes.

I have drag/dropped a button onto my Toolbar in IB and I need to add functionality to it that goes beyond just navigating to a new screen. Where and how can I implement this?

Thanks

Upvotes: 0

Views: 145

Answers (3)

Sebastian Flückiger
Sebastian Flückiger

Reputation: 5555

you only need an IBAction in your viewController, the button outlet is not really needed.

the function should look like that:

-(IBAction)doSomething:(id)sender;

wheras (id)sender references the control that initiated the control. if multiple buttons use this action, you can use the sender object to determine which one it was (might spare you from setting up multiple functions)

and add your functionality there. in InterfaceBuilder you can then click on your button, go to connections and choose the way you want to click the button (normally touch up inside) , drag it to your files owner and chose the IBAction you just declared.

Upvotes: 1

tallybear
tallybear

Reputation: 417

In addition to bschultz's answer... When you set up the IBAction put the things that you want the button to do within it. The IBOutlet is not needed as much as the IBAction. Once you have it set up, go to IB, Ctrl-Click on your button and drag the little line that shows up to File's Owner. Select your IBAction. You're done.

Upvotes: 0

bschultz
bschultz

Reputation: 4254

Set up the button with an IBOutlet and IBAction, then you can do what you need to do in code.

UIKit Constants Ref

Upvotes: 0

Related Questions