iOS SDK:单击按钮时关闭键盘? [英] iOS SDK: Dismiss keyboard when a button gets clicked?

查看:70
本文介绍了iOS SDK:单击按钮时关闭键盘?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户单击按钮时,如何关闭键盘? 一个简短的示例,它可以帮助您更好地理解:用户在某些文本字段中编辑了一些文本,最后他没有单击键盘上的完成"或其他操作,而是在仍然显示键盘时单击保存"按钮.那么,现在如何关闭键盘呢?

How can I dismiss the keyboard when the user clicks a button? A short example for a better understanding: the user edits some text in some textfields and at the end he doesn't click "Done" or smething else on the keyboard, but he clicks on an button "Save" while the keyboard is still shown. So, how can I now dismiss the keyboard?

Thx.问候,丹尼尔

Thx. Regards, Daniel

推荐答案

按钮操作写入,

if([textField isFirstResponder]){
  [textField resignFirstResponder];
}

如果有更多文本字段,则在开始编辑时每次获取当前文本字段引用,然后通过按钮操作将其响应者辞职.

if there are more textfields get the current textfield reference everytime while editing started, and resign its responder in button action.

这篇关于iOS SDK:单击按钮时关闭键盘?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆