Avatar ·

How to programmatically trigger a tap gesture handler on a UIView in Swift?

Hello! I'm a beginner in iOS development with Swift, and I have a problem. I added a UITapGestureRecognizer to a UIView, and it works perfectly when the user taps the view manually. But I need to programmatically simulate this tap — for example, when a push notification arrives or after data loads, so that the same handler gets triggered. I tried calling the method directly, but it doesn't work as expected. Here's my code: ```swift class ViewController: UIViewController { @IBOutlet weak var myView: UIView! override func viewDidLoad() { super.viewDidLoad() let tap = UITapGestureRecognizer(target: self, action: #selector(handleTap(_:))) myView.addGestureRecognizer(tap) } @objc func handleTap(_ sender: UITapGestureRec