How to check tap on the button? Swift
How to check tap on the button? Swift
I need to check when User taps the button to do next actions. How it can be implemented? For example, I have this button:
@IBAction func ButtonSender(_ sender: UIButton) {
}
and I need to know when it is tapped.
when user will tap the button(yourButton) and is connected to method @IBAction func ButtonSender(_ sender: UIButton) you can print something here
– Ajay Singh Thakur
Jul 3 at 9:49
Could you explain what's the problem?! your code snippet should be executed when user taps the button... what else?
– Ahmad F
Jul 3 at 9:53
your code is right, you will get the above event when button will tap
– arpita
Jul 3 at 10:27
2 Answers
2
This is very simple
@IBAction func ButtonSender(_ sender: UIButton) {
yourFunction()
print("The button was tapped")
}
Wondering how could you understand the purpose of the question :D
– Ahmad F
Jul 3 at 10:02
@AhmadF awesome developer :)
– Vyacheslav
Jul 3 at 10:03
Build a variable of type Boolean initialize it with false then after hitting button change its value to true..
@IBAction func ButtonSender(_ sender: UIButton) {
isButtonTapped = true
}
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Possible duplicate of Button tap and long press gesture
– sɐunıɔןɐqɐp
Jul 3 at 9:43