我有一个使用 UISearchBar
和 UISearchDisplayController
的iPhone应用程序。搜索栏有三个范围按钮。当选择特定的范围按钮时,我希望键盘是数字键盘,而其他任何范围按钮被选择时,则为默认键盘。
我已经实现了 UISearchBarDelegate
的 selectedScopeButtonIndexDidChange:selectedScope
方法如下:
- (void)searchBar:(UISearchBar *)searchBar selectedScopeButtonIndexDidChange:(NSInteger)selectedScope
{
switch (selectedScope) {
case DeviceIDScopeIndex:
searchBar.keyboardType = UIKeyboardTypeNumberPad;
break;
default:
searchBar.keyboardType = UIKeyboardTypeDefault;
break;
}
}
我知道当选择相关按钮时,方法会被调用并且正确的情况会触发。但是屏幕上的键盘除非我点击取消按钮来隐藏键盘,然后再次点击搜索框才能弹出键盘,不然它就不会改变。有没有办法在键盘显示时使其自己改变,或者编程方式隐藏然后重新显示键盘?