Here is an example of how to implement in Xamarin.iOS. There may be other simpler ways to do this, but I could not find them, and this works for me.
I subclassed UITextFieldDelegate to add a special event handler, then instantiated it in my view controller code, assigned a lambda expression to a custom event handler, to access the instance variables and set this delegate instance as a delegate to my 2 ext fields:
public class LoginTextFieldDelegate : UITextFieldDelegate { public EventHandler<UITextField> OnShouldReturn; public override bool ShouldReturn(UITextField textField) { if (OnShouldReturn != null) { OnShouldReturn(this, textField); } return true; } }
Then in my view the controller's ViewDidLoad method:
var textDelegate = new LoginTextFieldDelegate { OnShouldReturn = (sender, textField) => { if (textField.Tag == txtEmailAddress.Tag) { txtPassword.BecomeFirstResponder(); } else if (textField.Tag == txtPassword.Tag) { txtPassword.ResignFirstResponder(); } } }; txtEmailAddress.Delegate = textDelegate; txtPassword.Delegate = textDelegate;
Do not forget to set a separate tag on each UITextField in the code / interface builder!
Breeno
source share