如何在iOS中以编程方式使键盘消失
问题描述:
我无法在输入文本后让键盘消失。我有Xcode的以前版本的许多解决方案,但没有对的Xcode 7.我现在ViewController.h文件看起来像:如何在iOS中以编程方式使键盘消失
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController <UITextFieldDelegate>
@property (strong, nonatomic) IBOutlet UITextField *txtUsername;
@property (strong, nonatomic) IBOutlet UITextField *txtPassword;
@end
我.m文件看起来像:
#import "ViewController.h"
@interface ViewController()
@end
@implementation ViewController
@synthesize txtUsername;
@synthesize txtPassword;
- (void)viewDidLoad {
[super viewDidLoad];
self.txtUsername.delegate = self;
self.txtPassword.delegate = self;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
- (BOOL) textFieldShouldReturn:(UITextField *)textField {
[textField resignFirstResponder];
return YES;
}
@end
我已经分配从textField委托给ViewController。
更新我正在使用的视图未分配给ViewController类,因此没有继承我需要的textFielfShouldReturn方法。
有你,如果'testFieldShouldReturn验证:'方法实际上是被称为? – rmaddy
您的IBOutlets是否已连接? – EmilioPelaez
@EmilioPelaez我有插座连接到ViewController – BlackAperture