Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to connect multiple buttons in a storyboard to a single action?

Tags:

I'm currently using Xcode 4.6 and I'm simply wondering how to select multiple buttons across different UIViews, but under a single view controller. CMD clicking doesn't seem to work. I need this functionality because in Xcode 4.6 the only way to let two buttons on IB to share the same action is to select them at once and then drag the action to your view controller.

My ultimate goal is to get two different buttons on two different UIViews to match the same action using storyboards in Xcode 4.6. Is there a way to do this?

EDIT: I'm currently using Xcode 4.6.1 without any luck, upgrading to 4.6.2.

like image 996
jab Avatar asked Apr 17 '13 02:04

jab


2 Answers

You can connect multiple buttons to a single action without selecting them all at once.

However, after creating the action, you need to save the source file containing the action before Xcode will let you connect another control to the action.

I did this with Xcode 4.6.2:

connecting buttons to action

like image 178
rob mayoff Avatar answered Oct 12 '22 00:10

rob mayoff


Swift 3.0 Xcode 8.0+

Connect all buttons to below method signature. Make sure argument sender is of type UIButton (Or subclass of UIButton) in-order to connect rest of the buttons from storyboard.

@IBAction func dialconfigTapped(_ sender: UIButton) {} 

Use sender.tag to identify the tapped button.

like image 23
San Avatar answered Oct 12 '22 00:10

San