[英]How to hides the keyboard when we use the UITextView?
我正在开发一个应用程序。在这种情况下,我使用textview。但是,当我们单击textview或完成将文本输入到textview中时,不会触发textview委托方法。我也写了textview.delegate = self。但是它们没有触发所以请告诉我如何解决这个问题
The UITextViewDelegate
methods do not handle dismissal of the keyboard: you must do that yourself, by calling: UITextViewDelegate
方法不处理键盘的UITextViewDelegate
:您必须自己执行以下操作:
[textView resignFirstResponder];
This will then trigger the textViewShouldEndEditing:(UITextView *)textView
delegate method. 然后,这将触发textViewShouldEndEditing:(UITextView *)textView
委托方法。 What you need to do is call the resignFirstResponder
method in response to whatever actions you require - if this is tapping outside the text view you'll need to create a gesture recognizer / button / whatever to pick up that tap and call resignFirstResponder
. 您需要做的是调用resignFirstResponder
方法,以响应您需要执行的任何操作-如果在文本视图之外点击,则需要创建一个手势识别器/按钮/任何东西来拾取该点击并调用resignFirstResponder
。
You can also use Keyboard notifications like: 您还可以使用键盘通知,例如:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillShow)
name:UIKeyboardWillShowNotification object:nil];
and in -(void) keyboardWillShow {}
set [myTextField resignFirstResponder];
并在-(void) keyboardWillShow {}
设置[myTextField resignFirstResponder];
hope this helps. 希望这可以帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.