textFieldShouldEndEditing 不显示下一步/完成按钮键盘
textFieldShouldEndEditing not display Next / Done buttons keyboard
我无法使用 "Next" 或 "Done" 浏览我的表单文本字段。我尝试将 UITextFieldDelegate
添加到我的 UIViewController
并委托我的 UITextField
。我尝试根据 this post 修改我的代码,但仍然无效。
UIViewController.h
@interface MyViewController : UIViewController<UITextFieldDelegate, UIAlertViewDelegate> {
@property (nonatomic, strong) UITextField *usernameTextfield;
@property (nonatomic, strong) UITextField *passwordTextfield;
}
UIViewController.m
@implementation MyViewController
@synthesize usernameTextfield, passwordTextfield;
self.usernameTextfield = [[UITextField alloc] initWithFrame:CGRectMake(10,25, SCREEN_WIDTH-20, 35)];
self.usernameTextfield.delegate = self;
self.passwordTextfield = [[UITextField alloc] initWithFrame:CGRectMake(10,95, SCREEN_WIDTH-20, 35)];
self.passwordTextfield.secureTextEntry = TRUE;
self.passwordTextfield.delegate = self;
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
if (textField == self.passwordTextfield) {
[textField resignFirstResponder];
} else if (textField == self.usernameTextfield) {
[self.passwordTextfield becomeFirstResponder];
}
return YES;
}
欢迎任何想法。提前致谢!
这里有一个解决此类问题的快速简便的解决方案:IQKeyboardManager
GitHub : https://github.com/hackiftekhar/IQKeyboardManager
您将在 GitHub 上找到演示 GIF、演示视频和演示项目。
我无法使用 "Next" 或 "Done" 浏览我的表单文本字段。我尝试将 UITextFieldDelegate
添加到我的 UIViewController
并委托我的 UITextField
。我尝试根据 this post 修改我的代码,但仍然无效。
UIViewController.h
@interface MyViewController : UIViewController<UITextFieldDelegate, UIAlertViewDelegate> {
@property (nonatomic, strong) UITextField *usernameTextfield;
@property (nonatomic, strong) UITextField *passwordTextfield;
}
UIViewController.m
@implementation MyViewController
@synthesize usernameTextfield, passwordTextfield;
self.usernameTextfield = [[UITextField alloc] initWithFrame:CGRectMake(10,25, SCREEN_WIDTH-20, 35)];
self.usernameTextfield.delegate = self;
self.passwordTextfield = [[UITextField alloc] initWithFrame:CGRectMake(10,95, SCREEN_WIDTH-20, 35)];
self.passwordTextfield.secureTextEntry = TRUE;
self.passwordTextfield.delegate = self;
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
if (textField == self.passwordTextfield) {
[textField resignFirstResponder];
} else if (textField == self.usernameTextfield) {
[self.passwordTextfield becomeFirstResponder];
}
return YES;
}
欢迎任何想法。提前致谢!
这里有一个解决此类问题的快速简便的解决方案:IQKeyboardManager
GitHub : https://github.com/hackiftekhar/IQKeyboardManager
您将在 GitHub 上找到演示 GIF、演示视频和演示项目。