输入文字后我无法让键盘消失。我为Xcode的早期版本提供了许多解决方案,但Xcode 7没有任何解决方案。我当前的ViewController.h文件如下所示:
#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方法。
答案 0 :(得分:5)
尝试:
[self.view endEditing:YES];