textFieldShouldBeginEditing: Only Recognizes 1 textField
ios, objective-c, uitextfield
Solution
Are you setting the delegate for the text fields anywhere?
self.txtUser.delegate=self;
self.txtPass.delegate=self;
Also make sure you implement UITextFieldDelegate on your view controller.
@interface YourViewController: UIViewController<UITextFieldDelegate>
Problem
I have two text fields in my interface. txtUser allows the user to enter their username and txtPass allows the user to enter their password. I have programmatically assigned tags in the viewDidLoad method. I use these tags in order to identify the different text fields. The issue is that the textFieldShouldBeginEditing method only recognizes txtPass, while ignoring the txtUser. Both of these variables are linked to their respective text fields, so that's not what's causing the issue. Below is my code: ``` - (void)viewDidLoad{ [super viewDidLoad]; self.txtUser.tag=10; self.txtPass.tag=20; } - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{ if (textField.tag == 10){ self.btnNext.enabled = YES; self.btnPrevious.enabled = NO; }else if(textField.tag == 20){ self.btnNext.enabled = NO; self.btnPrevious.enabled = YES; } return YES; } ```