Xamarin iOS - Navigate to next text field with return key
ios, xamarin
Solution
You could make use of these functions
http://iosapi.xamarin.com/?link=M%3aMonoTouch.UIKit.UIResponder.BecomeFirstResponder
BecomeFirstResponder()
and
http://iosapi.xamarin.com/?link=M%3aMonoTouch.UIKit.UIResponder.ResignFirstResponder
ResignFirstResponder()
According to the documentation you should add the textField Delegate method like this
public virtual bool ShouldReturn (UITextField textField)
{
if (txtUsername.tag == 1) {
UITextField txtPassword = (UITextField)this.view.ViewWithTag(2);
txtPassword.BecomeFirstResponder();
}
else {
txtUsername.ResignFirstResponder();
}
return true;
}
Problem
I couldn't find anything in the Xamarin documentation about navigating to the next text field in a series of text fields on a form, only a small tutorial on removing the keyboard. To keep things simple I am using a txtUsername(tag 1) text field and a txtPassword(tag 2) text field. When I implement the following code, it isn't transferring to Xamarin Studio. Does anyone know the way this can be done code in Xamarin Studio, or alternatively if I can transfer the code from XCode to Xamarin Studio. I am using the following code: ``` - (BOOL)textFieldShouldReturn:(UITextField *)txtUsername{ NSLog(@"textFieldShouldReturn:"); if (txtUsername.tag == 1) { UITextField *txtPassword= (UITextField *)[self.view viewWithTag:2]; [txtPassword becomeFirstResponder]; } else { [txtUsername resignFirstResponder]; } return YES; } ``` Thanks in advance