4

I have a UITextView connected from Storyboard, call it txtView. In my ViewController I set the delegate like txtView.delegate = self.

The view controller fires method like textViewDidBeginEditing and textViewDidChange, but not func textView(_ textView: UITextView, shouldChangeTextIn range: NSRange, replacementText text: String) -> Bool

Yes, I did set the delegate in my view controller.

Yes, I did put UITextViewDelegatein my class declaration

No, I did not confuse UITextView with UITextField.

Any idea? Thanks!

class ViewController: UIViewController, UITextViewDelegate, UIGestureRecognizerDelegate {
  @IBOutlet weak var txtView: UITextView!

  override func viewDidLoad() {
    super.viewDidLoad()
    txtView.delegate = self
    txtView.becomeFirstResponder()  
    txtView.text = "txt"
  }

  func textViewDidChange(_ textView: UITextView) {
    print("THIS PRINTS")
  }

  func textView(_ textView: UITextView, shouldChangeTextIn range: NSRange, replacementText text: String) -> Bool {
    print("WHY DOESN'T THIS GET CALLED?")
    return true
  }
}
Losiowaty
  • 7,911
  • 2
  • 32
  • 47
7ball
  • 2,183
  • 4
  • 26
  • 61
  • Can you paste your code? – Losiowaty Aug 26 '16 at 22:26
  • Done. It never calls the second delegate method... – 7ball Aug 26 '16 at 23:17
  • With exactly the same code, the second delegate is called. (I get "WHY DOESN'T THIS GET CALLED?" in Xcode console.) Can you reproduce the same issue with exactly the same code you have shown? Something hidden may be affecting. – OOPer Aug 27 '16 at 02:44

0 Answers0