Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't drag button action to existing function in Xcode 8

I have a weird issue with Xcode 8. When I try to ctrl + drag button to existing function, I can't I can only create new outlet or Action. What is more weird, that even when I create action by ctrl + drag i can't connect event the same button that I used for creating action. IB icon is also blank like there is no connection between action and button, but real time clicking runs action. On the other hand when I try to connect action to button from swift to storyboard I can (@IB icon becomes "full"), but then I get exception on real time clicking unrecognized selector myActionWithSender enter image description here enter image description here

like image 507
Jarosław Krajewski Avatar asked Sep 20 '16 21:09

Jarosław Krajewski


People also ask

How do I assign an action button in Xcode?

You need to first select your button, then hold the control ⌃ button on your keyboard and then drag that across to your view controller. That will then give you the option of what to name your method etc.

How can I check if UIButton is pressed?

If you want to check If UIButton is Pressed or not, You should handle TouchDown Handler and change button's state to pressed in touchDown hadnler. You can track ToucUpInside method to Change state of button to Not-pressed again.

How do I create an action in Xcode?

Hold down the Control key and drag (or right-click-and-drag) from the control in question over into your class @interface . Let the mouse button go when Xcode indicates a successful drag with a horizontal line. In the window that pops up, choose whether you want to create an outlet or an action.


4 Answers

In my Xcode version, IBAction is created automatically with "Any" parameter, instead of "AnyObject". Creating IBAction explicitly with UIButton instead worked for me.

like image 179
Umut Uygar Avatar answered Oct 27 '22 15:10

Umut Uygar


In my case, you will need to change Any to UIButton. It need to be specific that the action coming from UIButton.

@IBAction func buttonClicked(_ sender: UIButton) {  } 
like image 44
Didats Triadi Avatar answered Oct 27 '22 15:10

Didats Triadi


Click on the UIButton, then go to "Connections Inspector" from Utilities area.

Click on the empty circle beside the event and drag the line into func body.

like image 33
Alaa Qaddoumi Avatar answered Oct 27 '22 15:10

Alaa Qaddoumi


right click with open button function in select touchup inside to drag ..u should try this..

like image 31
ronak patel Avatar answered Oct 27 '22 14:10

ronak patel