调用dismissKeyboard 时,我将每个UITextField 添加到resignFirstResponder。
有没有办法我可以获取当前选定的 UITextField 的 id 并将其设为 resignFirstResponder?
#import "NewBabyViewController.h"
@interface NewBabyViewController ()
@property (weak, nonatomic) IBOutlet UITextField *BabyName;
@property (weak, nonatomic) IBOutlet UITextField *BabyNickname;
@end
@implementation NewBabyViewController
- (void)viewDidLoad
{
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]
initWithTarget:self
action:@selector(dismissKeyboard)
];
[self.view addGestureRecognizer:tap];
}
-(void)dismissKeyboard{
[self.view endEditing:YES];
//[self.BabyName resignFirstResponder];
//[self.BabyNickname resignFirstResponder];
}
-(IBAction)textFieldDone:(id)sender
{
[sender resignFirstResponder];
}
@end