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
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.
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.
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.
In my Xcode version, IBAction is created automatically with "Any" parameter, instead of "AnyObject". Creating IBAction explicitly with UIButton instead worked for me.
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) { }
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.
right click with open button function in select touchup inside to drag ..u should try this..
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With