Kri*_*son 13 iphone cocoa-touch uisearchbar
我有一个使用UISearchBar
和的iPhone应用程序UISearchDisplayController
.搜索栏有三个范围按钮.我希望键盘在选择特定范围按钮时成为数字键盘,但在选择任何其他范围按钮时成为默认键盘.
我已经实现了UISearchBarDelegate
selectedScopeButtonIndexDidChange:selectedScope
如下方法:
- (void)searchBar:(UISearchBar *)searchBar selectedScopeButtonIndexDidChange:(NSInteger)selectedScope
{
switch (selectedScope) {
case DeviceIDScopeIndex:
searchBar.keyboardType = UIKeyboardTypeNumberPad;
break;
default:
searchBar.keyboardType = UIKeyboardTypeDefault;
break;
}
}
Run Code Online (Sandbox Code Playgroud)
我知道该方法被调用,并且当选择了相关按钮时会触发正确的情况.但屏幕键盘不会改变,除非我点击取消按钮隐藏键盘,然后再次点击搜索字段再次调出键盘.
有没有办法让键盘在屏幕上改变自己,或以编程方式隐藏它然后重新显示它?
小智 24
如果您使用的是iOS 3.2或更高版本,可以致电:
[searchBar reloadInputViews]
Run Code Online (Sandbox Code Playgroud)
并且它立即切换而没有hackery.至少这对我在UITextField上有用.(我提到这个是因为辞职/成为第一响应者技巧并不适合我,但是reloadInputViews确实如此.)
小智 23
即使这是一种黑客攻击,这对我有用:
- (void)searchBar:(UISearchBar *)searchBar selectedScopeButtonIndexDidChange:(NSInteger)selectedScope {
switch (selectedScope) {
case 0:
searchBar.keyboardType = UIKeyboardTypeNumberPad;
break;
default:
searchBar.keyboardType = UIKeyboardTypeDefault;
break;
// Hack: force ui to reflect changed keyboard type
[searchBar resignFirstResponder];
[searchBar becomeFirstResponder];
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
12352 次 |
最近记录: |