我无法使用" Next"浏览我的表单文本字段。或者"完成"。我尝试将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;
}
任何想法都会受到欢迎。提前谢谢!
答案 0 :(得分:1)
这是管理这类问题的快速简便的解决方案: IQKeyboardManager
GitHub: https://github.com/hackiftekhar/IQKeyboardManager
您可以在GitHub上找到演示GIF,演示视频和演示项目。