3

Using the Reflection API to auto generate a UI.

How can I dismiss the keyboard when the user selects a new field, or if they choose a field which generates a new view to pick from. In the later case, when the user returns to the first screen, the old keyboard is still there.

Ian Vink
  • 66,960
  • 104
  • 341
  • 555

3 Answers3

9
UIView.EndEditing(bool force);

The above will hide the keyboard for you without needing to know who the first responder is. I haven't done much with the reflection API but you should be able to call that on the view when an element is selected.

Apple Docs -- endEditing:

BLeB
  • 1,716
  • 17
  • 24
5

Clarification for those initially struggling with the MonoDialog portion of the question:

The EndEditing method is not available on DialogViewControllers objects directly (who inherit from UITableViewControllers). You should be calling EndEditing(bool) on the View of a DialogViewController and not trying to call EndEditing(bool) on the actual DialogViewController itself.

For clarification:

DialogViewController dc; dc.View.EndEditing(true);

Note: UIView objects include the EndEditing(bool) method, but UITableViewControllers do not inherit from UIView so the EndEditing method is not available on the controller itself. UITableViewControllers contain a view object, call EndEditing on that view object.

benhorgen
  • 1,928
  • 1
  • 33
  • 38
0

Check the ResignFirstResponder method. This one should help you I guess.

Scarlaxx
  • 835
  • 1
  • 6
  • 13