MonoTouch.Dialog: Dismissing a Keyboard

半腔热情 提交于 2019-12-10 19:45:29

问题


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.


回答1:


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:




回答2:


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.




回答3:


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



来源:https://stackoverflow.com/questions/7408937/monotouch-dialog-dismissing-a-keyboard

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!