Can I detect gestures on an UITextView object via the story board editor

I have the code below, copyright Paul Hudson, from one of his lessons online. And it works just fine. But I tried to also capture the tapping gesture through Xcode's IDE ctrl-drag method.

That method only allows me to create an IBOutlet connection.

I was hoping there was a way to do this through the IDE, just to make things quicker? When I did someone else's lesson online, ctrl-dragging a button (with Asst. Editor) did allow me to add and @IBAction connection.

If anyone can tell me if there is something I am missing?

Thank you

Code Block
import UIKit
class MemoryViewController: UIViewController {
    @IBOutlet weak var textView: UITextView!
    var item: MemoryItem!
    var blankCounter = 0
    override func viewDidLoad() {
        super.viewDidLoad()
        showText()
// capture tap gesture from touchscreen
            let tapRecognizer = UITapGestureRecognizer(target: self, action: #selector(wordsTapped))
        textView.addGestureRecognizer(tapRecognizer)
 }
    func showText()
    {
// code to fill cell
    }
    @objc func wordsTapped()
    {
....misc code
        showText()
    }
}


Answered by Claude31 in 613518022
You need to do things in the order I told you:
  1. drag a tapGesture onto the textView.

  2. Then connect the tapGesture to its IBAction (open connection Inspector) and control-drag from selector button to the code to create the IBAction.

You should be able to drag a tapGesture onto the textView.

Then connect the tapGesture to its IBAction (open connection Inspector) and control-drag from selector button to the code to create the IBAction.
Maybe that's what I'm missing or stated incorrectly. I can Ctrl+Drag from a button and it gives me all options:

"Insert Action, Outlet, or OutletCollection"

But if I Ctrl+Drag from an ImageView or a TextView it only allows the two Outlet options.

Is it a method that's not part of those classes, and if so can I add it to them?


You need to add Tap Gesture Recognizer to the Text View, first.
And then, you can Ctrl-Drag from the Tap Gesture Recognizer to your code.
Accepted Answer
You need to do things in the order I told you:
  1. drag a tapGesture onto the textView.

  2. Then connect the tapGesture to its IBAction (open connection Inspector) and control-drag from selector button to the code to create the IBAction.

Can I detect gestures on an UITextView object via the story board editor
 
 
Q