我有一个使用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;
}
}
我知道该方法被调用,并且在选择相关按钮时触发了正确的情况。但是屏幕键盘不会改变,除非我点击取消按钮隐藏键盘,然后再次点击搜索字段以再次调出键盘。
有没有办法让键盘在屏幕上改变自己,或者以编程方式隐藏它然后重新显示它?