我有一个UIPopoverController
,其中包含UITableViewController
。另外,我正在使用UISearchDisplayController
。
我的类界面是这样的:
@interface SearchController : UITableViewController <UITableViewDataSource, UITableViewDelegate, UIPopoverControllerDelegate, UISearchDisplayDelegate, UISearchBarDelegate> {
UISearchBar *_searchBar;
UISearchDisplayController *_searchDisplayVC;
}
我的init看起来像这样:
//create a search bar
_searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
_searchBar.delegate = self;
_searchDisplayVC = [[UISearchDisplayController alloc] initWithSearchBar:_searchBar contentsController:self];
self.searchDisplayController.delegate = self;
self.searchDisplayController.searchResultsDataSource = self;
self.searchDisplayController.searchResultsDelegate = self;
// add a searchbar
self.tableView.tableHeaderView = _searchBar;
我的问题是,当我选择搜索栏在其中输入搜索词组时,即使尝试这样做,键盘也不会被忽略:
- (BOOL)searchBarShouldEndEditing:(UISearchBar *)searchBar {
[searchBar resignFirstResponder];
return YES;
}
- (void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController {
NSLog(@"Dismiss popover controller");
[_searchBar becomeFirstResponder];
[_searchBar resignFirstResponder];
}
- (void)searchBarTextDidEndEditing:(UISearchBar *)searchBar {
//trying to resolve the issue with not working automatic hiding of a keyboard.
[searchBar resignFirstResponder];
[searchBar endEditing:YES];
}
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar{
[TableSearchViewController dismissKeyboard];
}
-(BOOL)disablesAutomaticKeyboardDismissal {
return NO;
}
+ (void)dismissKeyboard {
[[[[UIApplication sharedApplication] delegate] window] endEditing:YES];
}
任何人都知道如何解雇键盘?
答案 0 :(得分:2)
我找到了解决这个问题的方法。
在父视图控制器中,我已将名为UIViewController
的{{1}}方法覆盖为:
disablesAutomaticKeyboardDismissal
它工作正常! :)键盘按预期隐藏。 感谢@ujell对此问题感兴趣:)