I'm not able to navigate through my form textfields with "Next" or "Done". I tried to add UITextFieldDelegate
to my UIViewController
and delegate my UITextField
. I tried to modify my code according to this post but still not work.
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;
}
Any idea will be welcomed. Thanks in advance !
Here's a fast and easy solution to manage these kind of problems : IQKeyboardManager
GitHub : https://github.com/hackiftekhar/IQKeyboardManager
You'll find a demo GIF, a demo video, and a demo project on the GitHub.