Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I am using Xcode 8 beta. I cannot drag multiple UIButtons from storyboard to connect to a single @IBAction in swift file. Bug? Thanks for your help.

like image 309
Anthony D. Avatar asked Jun 15 '16 21:06

Anthony D.


2 Answers

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! :)

like image 61
Chathuranga Silva Avatar answered Oct 02 '22 20:10

Chathuranga Silva


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.

like image 45
Sean Avatar answered Oct 02 '22 18:10

Sean