我在另一个文件中有一个带有数据源/委托(delegate)的 TableView 。另外,在属于第一个文件的 TableView 上方有一个搜索栏。在滚动时隐藏键盘,我需要调用:
[self.searchBar resignFirstResponder]
但是
(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
方法在委托(delegate)中。那么在这种情况下滚动时如何隐藏键盘呢?
谢谢!
最佳答案
您可以在 scrollviewwillbegindragging 中发送通知。 TableView 委托(delegate):
-(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{
[[NSNotificationCenter defaultCenter] postNotificationName:@"resign" object:nil];
}
搜索栏委托(delegate):
-(void)viewDidLoad{
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(goTo:) name:@"resign" object:nil];
}
-(void)goTo:(NSNotification*)notification {
[self.searchBar resignFirstResponder];
}
关于iphone - 外部 UITableView 委托(delegate)如何隐藏 UISearchBar 键盘?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11962788/