我無法在輸入文本後讓鍵盤消失。我有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