can multiple buttons be attached to a single IBAction is Xcode 8?

这一生的挚爱 提交于 2019-12-08 10:17:44

问题


I have tried to connect several buttons to a single IBAction in Xcode 8 however it does not work. I tried the practices outlined here Xcode8 cannot connect multiple/single uibuttons to single @IBAction in swift file still to no avail. can anyone shed some light as to why or if it is simply still just a bug?


回答1:


Works fine for me in Xcode 8.1 on a new Swift 3 project. You have to control-drag from the button to the center side of the method to select it if it already exists rather than drag to the left side.




回答2:


change your parameter from (_ sender: Any) to (_ sender: UIButton), and you're good to go.




回答3:


There is no reason why several buttons should not connect to a single action function in your code. I had no trouble doing this when I tried it, as you can see:

However, if the nib editor interface won't let you form the connection, configure the action-target of the buttons in code.




回答4:


Double check if you want to add action to a real button Check if when you wrote the action, you used some customized class instead of UIButton, and the class of your button does not match.




回答5:


I was able to resolve the issue by upgrading to Xcode 8.1 and including an _ before the sender argument. I believe this is just a bug from Xcode 8 because I tried the latter before upgrading and I was still unable to connect.



来源:https://stackoverflow.com/questions/40353024/can-multiple-buttons-be-attached-to-a-single-ibaction-is-xcode-8

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!