1

i want to implement an onClick event with a UILabel. It prints "hello", so the viewDidLoad() method gets called. I've connected the UILabel using Storyboard. I don't see why this code is not working. Do you guys see it ?

import UIKit


class AlternativeSignUpViewController: UIViewController {

    @IBOutlet weak var x: UILabel!

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.


        let gestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(AlternativeSignUpViewController.handleTap(_:)))
        x.addGestureRecognizer(gestureRecognizer)
        print("hello")

    }

    func handleTap(gestureRecognizer: UIGestureRecognizer) {
        print("tapped")
    }


}
reBourne
  • 127
  • 1
  • 1
  • 9

0 Answers0