UITextView 在“完成”时放弃第一响应者;
我已经在网上搜索了大约一个小时,但找不到任何代码来帮助我解决这个问题。
我有一个 UITextView,当用户按下键盘上的“完成”按钮时,我需要放弃第一响应者。
我见过这样的代码在互联网上流传:
-(BOOL) textFieldShouldReturn:(UITextField *)textField {
[textField resignFirstResponder];
return NO;
}
但这不适用于 UITextView
。 简单地说, 如何判断用户何时按下键盘上的完成按钮?
I have been searching around the web for about an hour now, and cannot find any code to help me with this.
I have a UITextView
that I need to resign first responder of when the user presses the 'Done' button on their keyboard.
I have seen code floating around the internet like this:
-(BOOL) textFieldShouldReturn:(UITextField *)textField {
[textField resignFirstResponder];
return NO;
}
But that will not work for a UITextView
.
Simply put,
How can I tell when the user presses the done button on the keyboard?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用委托方法
您必须将控制器设置为 TextView 的委托。
有关更多方法,您可以查看这里: http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UITextViewDelegate_Protocol/Reference/UITextViewDelegate.html%23//apple_ref/doc/uid/TP40006897
You can use the delegate method
You have to set your controller as the delegate for the TextView.
For more methods you can have a look here: http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UITextViewDelegate_Protocol/Reference/UITextViewDelegate.html%23//apple_ref/doc/uid/TP40006897
实现
shouldChangeTextInRange:
委托方法。使用以下方法,该解决方案仅适用于 @"\n" (换行符)。
Implement the
shouldChangeTextInRange:
delegate method.Use below approach and the solution work only with @"\n" (new line character).