1

This is the same question as UIPicker detect tap / touch on currently selected row.

I am updating its Swift 2 solution to Swift 3. But my tap handler is never called for the PickerView. (It is if I attach the Recognizer to the background UIView.) I have an old Obj-C app that does the same thing -- successfully. So I think it should work.

Here's the setup.

override func viewDidLoad() {
    super...
    let tgr = UITapGestureRecognizer(
        target:self, 
        action:#selector(tap(_:))
    )
    // self.view.addGestureRecognizer(tgr)     // This dispatches to tap().
    self.pickerView.addGestureRecognizer(tgr)  // This does not.
}

func tap(_ sender:UITapGestureRecognizer) {
    print("Tapped!")
}

It's also the case that the real handler for the tap needs Swift 3 rewriting. I got that and want to post the update in the original question. But somehow I can't even receive the gestures.

Community
  • 1
  • 1
Andrew Duncan
  • 3,553
  • 4
  • 28
  • 55

0 Answers0