Xcode8 cannot connect multiple/single uibuttons to single @IBAction in swift file

9 Solutions Collect From Internet About “Xcode8 cannot connect multiple/single uibuttons to single @IBAction in swift file”

By Using this workaround you can add existing action and also can connect multiple buttons to a single action.

I think there is a bug in Xcode8. You can add multiple/Single button to a single action /function by changing sender to _ sender

eg :- Normal Button

   @IBAction func huu(sender: UIButton) {

   }

You can’t add multiple buttons or single button to this action you need to simply change like this and then you can add multiple buttons by using drag and connect from storyboard.

 @IBAction func huu(_ sender: UIButton) {

 }

After connecting IBOutlets Xcode will show a warning like this :-

enter image description here

To remove this warning simple delete _ sign from the action/function. Make sure that to delete _ after connecting your IBOutlets

Hope that this will gonna help you! 🙂

If you change the sender to AnyObject as opposed to Any or UIButton it will allow you to connect multiple buttons to the same action.

When you connect a button action, by default the method will looks like :

@IBAction func s(_ sender: Any) {
    }

Just change Any to UIButton and you can connect more button actions to this particular method.

So after changing it should looks like this :

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

Hope this will solve the issue. 🙂

If you change “Any” to “UIButton” it will work.

If I am correct you need to use UIGestureRecognizer to attach multiple things to one action.

What you could do is place a UIGestureRecognizer on each button, and then setup one of them like you normally would with a button (ctrl-drag), than ctrl-drag from the other gesture recognizers to the first action you made.

I guess it’s another issue : if you try to create an IBAction the first time, it works fine.
But if for any reason you decide to re-connect the IBAction (same action to another object, or rename the function), then it fails.

In fact, you create an IBAction called doSomething, which creates a function func doSomething(sender: UIButton).
But with XCode 8 (or Swift 2.3 / 3.0), this method is interpreted as func doSomethingWithSender(sender: UIButton).

I guess it’s a bug, Apple went a bit too hard on the “rename Objc-methods” thing.

I have changed the sender to UIButton from Any

Control drag the button to the name of the function.

IN Swift 3 full version this will work.

Just change Any to UIButton and you can connect more button actions to this particular method.

So after changing it should looks like this :

@IBAction func s(_ sender: UIButton) {
}
Sure this will solve the issue. 🙂

I tried many times, at last, i got the result as,

Normal UIAction

@IBAction func selectBtn(_ sender: Any) {

   }

for Multiple Buttons with same UIAction method, try below method,

@IBAction func selectBtn(_ sender: UIButton) {

   }

This worked for me. I changed the return type from “Any” to “UIButton”