I’m trying to switch between the UIReturnKeyGo and the UIReturnKeyNext buttons depending on whether or not the user has entered some text in the fields or not, but it’s not working the way I was hoping it would. Here’s what I’m doing.
I created the following method:
- (void)setReturnKey {
if (self.isLoggingIn) {
if ([self.userField.text length] > 0 ||
[self.passField.text length] > 0) {
self.userField.returnKeyType = UIReturnKeyGo;
self.passField.returnKeyType = UIReturnKeyGo;
} else {
self.userField.returnKeyType = UIReturnKeyNext;
self.passField.returnKeyType = UIReturnKeyNext;
}
}
}
Then I added the above method to the textFieldDidBeginEditing delegate method, which will run anytime a field becomes active, and I created a textFieldDidChange method that is executed anytime text is entered or deleted. Unfortunately this is not working the way I hoped it would. The go button only appears when both fields are filled out and you actively click on another field, it doesn’t update when you begin typing. So I can type in my username, then click next and start typing in my password, but the go button doesn’t appear when I start entering my password, it will only show if I click the user field again.
Any idea what I’m doing wrong here or if there’s a better way to accomplish this?
This is a bad idea. You’ll just confuse the users. Keep the User field as Next and the Pass field as Go.