问题描述
在一个uitextview上隐藏键盘,有方法:
on a uitextview to hide the keyboard, there is the method:
... textfield.returnkeytype = uireturnkeydone; textfield.delegate = self; .... -(bool)textfieldshouldreturn:(uitextfield *)textfield { [textfield resignfirstresponder]; return yes; }
但是如果我想将完成"按钮留给返回"并添加一个隐藏键盘的按钮,我该怎么办?
but if i want to leave the button "done" to the "return" and add a button to hide the keyboard, how do i?
推荐答案
您可以分配一个带有按钮的工具栏,该按钮可作为文本字段的 inputaccessoryview 关闭键盘.一个简单的例子是,
you can assign a toolbar with a button that dismisses the keyboard as the text field's inputaccessoryview. a quick example would be,
uibarbuttonitem *barbutton = [[[uibarbuttonitem alloc] initwithbarbuttonsystemitem:uibarbuttonsystemitemdone target:textfield action:@selector(resignfirstresponder)] autorelease]; uitoolbar *toolbar = [[[uitoolbar alloc] initwithframe:cgrectmake(0, 0, 320, 44)] autorelease]; toolbar.items = [nsarray arraywithobject:barbutton]; textfield.inputaccessoryview = toolbar;