我知道这种方式UISearchBar with InputView
但我想知道是否有适当的"这样做的方法呢?比上面看起来更糟糕的方法更好,并且显然无法保证在未来版本的iOS SDK中可以使用。
我有一个搜索栏,带有分段控件(范围),并且我希望在其中一个范围内显示日期选择器而不是键盘。标准UISearchBar无法访问inputView
属性,那么还有其他方法吗?
非常感谢
汤姆
答案 0 :(得分:2)
仅限2分, 首先跟踪选定的范围 其次,只要选择了所需的范围,然后重新调整键盘并显示选择器。 也许这段代码可以帮到你。
#pragma mark - UISearchBarDelegate
- (void)searchBar:(UISearchBar *)searchBar selectedScopeButtonIndexDidChange:(NSInteger)selectedScope{
// Track the Scope Selection
selectedSearchType = selectedScope ;
}
- (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar {
if(selectedSearchType=="Scope_which_will_expose_picker"){
// Show Picker Here
[searchBar resignFirstResponder];
}
return YES;
}