UISearchBar键盘返回键 [英] UISearchBar Keyboard Return Key
问题描述
我正在使用UISearchBar将文本输入与数据库中的条目进行匹配,并在UITableView中显示匹配的结果,因为它们键入。
I am using a UISearchBar to match text input against entries in a database and display the matched results to the user in a UITableView, as they type.
所有是好吧,但是,我找不到改变搜索栏键盘返回键类型的方法。默认情况下,它使用 Search 按钮替换标准 return 键。因为我正在进行实时搜索,因为用户输入,我不需要这个按钮并且在那里使用并且不活动会引发一些可用性问题。
All is well, however, I cannot find a way to alter the return key type of the search bar's keyboard. By default it replaces the standard return key with a Search button. Because I am doing a live search as the user types, I do not need this button and having it there and inactive has raised some usability issues.
尝试的解决方案
-
我可以使用
setKeyboard设置键盘:UIKeyboardType
方法,但是这似乎没有覆盖用 Search 键替换返回键(在标准键盘上)的默认设置,并且它不允许访问更改此返回 key。
I can set a keyboard with the
setKeyboard:UIKeyboardType
method, however this doesn't seem to override the default setting of replacing the return key (on the standard keyboard) with a Search key and it does not allow access to change this return key.
我考虑过使用 UITextField
,让我可以访问通过 UITextInputTraits
协议 returnKeyType
属性。我的问题是,我正在实现 UISearchBarDelegate
方法 searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
,我将失去 UITextField
。
I have thought about using a UITextField
, giving me access to the returnKeyType
property through the UITextInputTraits
protocol. My problem with this however is that I am implementing the UISearchBarDelegate
method searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
, which I would lose with the UITextField
.
<有没有办法可以保持搜索栏的委托方法的功能,同时合法访问键盘的返回键?
Is there a way that I can keep the functionality of the search bar's delegate methods, whilst having legitimate access to the keyboard's return key?
事实上,几乎是准确的我正在实施的屏幕在Apple的时钟应用程序中找到
屏幕截图:
In fact, almost the exact screen I am implementing is found in Apple's Clock application
Screenshot:
因此,我们非常感谢任何有关清洁解决方案的帮助。请注意右下方的 return 键,而不是默认的搜索按钮。
So any help on a clean solution would be much appreciated. Note the return key on the bottom right instead of the default Search button'.
推荐答案
试试这个:
for(UIView *subView in searchBar.subviews) {
if([subView conformsToProtocol:@protocol(UITextInputTraits)]) {
[(UITextField *)subView setKeyboardAppearance: UIKeyboardAppearanceAlert];
}
}
如果要关闭返回键(即不做任何操作),请设置UITextField子视图中的returnKeyType属性为UIReturnKeyDone以及keyboardAppearence。
If you want to dismiss the return key (i.e., make it do nothing), set the "returnKeyType" property on the UITextField subview to "UIReturnKeyDone" along with "keyboardAppearence".
这篇关于UISearchBar键盘返回键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!