Setting the Focus to a UITextField

PDF for offline use
Sample Code:
Related SDKs:

Let us know how you feel about this

Translation Quality


0/250

Code can manually change the focus of a view to bring up the keyboard for entry in a UITextField without tapping it.

Recipe

Focus Screen

To have our UITextField, in this case named FocusTextField, selected as soon as we open the view, we can place the following line of code in the ViewDidLoad() method:

FocusTextField.BecomeFirstResponder ();

Additional Information

We can call BecomeFirstResponder on a UITextField at any point to switch focus - not just inside ViewDidLoad.

Xamarin Workbook

If it's not already installed, install the Xamarin Workbooks app first. The workbook file should download automatically, but if it doesn't, just click to start the workbook download manually.