[英]How to make the keyboard disappear programmatically in iOS
輸入文字后我無法讓鍵盤消失。 我為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方法。
嘗試:
[self.view endEditing:YES];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.