I have several UITextFields that are in a group... I need to be able to move from the first to the last, and on the last make it FirstResponder.
I thought the Next key would move the focus, and Done would cause it to become FirstResponder, but apparently not.
Ideas?
The "Accepted Answer" is right, but I thought a little code wouldn't hurt for people who are new to MonoTouch.
public override void ViewDidLoad () {
base.ViewDidLoad ();
// make first text field have focus
this.txtMake.BecomeFirstResponder();
// make 'return' shift focus to next text field
this.txtMake.ShouldReturn = delegate(UITextField textField) {
this.txtModel.BecomeFirstResponder ();
return true;
};
// make 'return' on last text field save and close the form
this.txtModel.ShouldReturn = delegate(UITextField textField) {
this.txtModel.ResignFirstResponder();
this.SaveAndClose ();
return true;
};
}
private void SaveAndClose() {
// todo: do something with your data
// navigate back
this.NavigationController.PopViewControllerAnimated(true);
}
Hope this helps others.
You have to implement the UITextFieldDelegate's ShouldReturn method and in there make the next text field BecomeFirstResponder(). Then return/next will take you to the next field. If return is hit on the last textfield you will call ResignFirstResponder() on that field.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With