[英]Dismissing the First Responder/Keyboard with multiple Textfields
Like seriously after going through this...在经历了这些之后,就像认真...
Easy way to dismiss keyboard? 关闭键盘的简单方法?
... I have multiple TextFields
and a few TextViews
. ...我有多个
TextFields
和一些TextViews
。 Is there not a way to a have a batch or group Dismiss First Responder for all text fields?有没有办法为所有文本字段设置批次或组 Dismiss First Responder? Will I need to make method for each field?
我需要为每个字段制作方法吗? Maybe I overlooked something in that link?
也许我忽略了该链接中的某些内容?
Maybe I can follow something like this:也许我可以遵循这样的事情:
https://stackoverflow.com/questions/3282837/problem-with-multiple-textfields-to-make-the-keyboard-dissapear https://stackoverflow.com/questions/3282837/problem-with-multiple-textfields-to-make-the-keyboard-dissapear
Would the latter make sense?后者有意义吗? Thanks in advance.
提前致谢。
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- =-
I figured it out....我想到了....
Controller.h
@interface Controller : UIViewController <UITextFieldDelegate> {
IBOutlet UITextField *clickedDone;
}
@property (nonatomic, retain) IBOutlet UITextField *clickedDone;
Controller.m
#import "Controller.h"
@implementation Controller
@synthesize clickedDone;
- (void)viewDidLoad
{
[super viewDidLoad];
[clickedDone setDelegate:self];
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
[textField resignFirstResponder];
return YES;
}
The view has an endEditing:
method you can use.该视图有一个
endEditing:
可以使用的方法。 The docs say文档说
Causes the view (or one of its embedded text fields) to resign the first responder status.
导致视图(或其嵌入的文本字段之一)放弃第一响应者状态。
In your view controller you can just call:在您看来 controller 您可以致电:
[[self view] endEditing:YES];
clickedDone.returnKeyType = UIReturnKeyDone; // in viewDidLoad
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder];
return YES;
}
Its very easy now.现在很容易。 You can follow different approach depending on your use cases.
您可以根据用例采用不同的方法。 In my case I had multiple textfields in UITableViewController.
就我而言,我在 UITableViewController 中有多个文本字段。 What I did is this:
我所做的是这样的:
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[self.view endEditing:YES];
}
Best answer is:最佳答案是:
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder];
return YES;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.