iphone - 外部 UITableView 委托(delegate)如何隐藏 UISearchBar 键盘?

标签 iphone objective-c ios cocoa-touch uitableview

我在另一个文件中有一个带有数据源/委托(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/

相关文章:

ios - 如何在 iPhone 应用程序的密码字段中隐藏文本?

ios - iOS drawInRect内存泄漏-ARC

ios - 在 Swift 3 中请求访问联系人

iphone - iPhone 应用程序的声音格式

iphone - CGContextSetShadow 不产生任何结果

iphone - 设计和 Rails 3 中的 http 身份验证

objective-c - Cocoa API 图像处理

ios - 套接字创建失败但 socket() 和 bind() 方法不返回 -1

ios - 使用我自己的 UIButton 获取用户 Facebook 信息

iphone - 在 UITableViewCell 图像上设置 UIImage 尺寸