0

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 !

Community
  • 1
  • 1
user3405644
  • 195
  • 1
  • 2
  • 11

1 Answers1

1

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.

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
Jonathan F.
  • 2,357
  • 4
  • 26
  • 44