我从故事板连接了UITextView
,称之为txtView
。在我的ViewController
中,我将代理设置为txtView.delegate = self
。
视图控制器会触发textViewDidBeginEditing
和textViewDidChange
之类的方法,但不会触发func textView(_ textView: UITextView, shouldChangeTextIn range: NSRange, replacementText text: String) -> Bool
是的,我确实在我的视图控制器中设置了delegate
。
是的,我确实将UITextViewDelegate
放入了我的班级声明
不,我没有将UITextView
与UITextField
混淆。
有什么想法吗?谢谢!
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
}
}