我的键盘显示为textView,我想在用户按下导航栏上的后退按钮时隐藏它。
我试过这个:
-(void)viewWillDisappear:(BOOL)animated{
[myTextView resignFirstResponder];
}
和此:
-(void)viewDidDisappear:(BOOL)animated{
[myTextView resignFirstResponder];
}
但它不起作用,我怎么能这样做?
编辑:
我在这里找到了解决方案:
答案 0 :(得分:17)
将其放入buttonPress方法 -
[self.view.window endEditing:YES];
编辑 - 这也可以让您在按下“后退”按钮时获取正在编辑的文本的内容
答案 1 :(得分:3)
结合上述答案和检查后退按钮将由此
完成- (void)viewWillDisappear:(BOOL)animated{
if ([self.navigationController.viewControllers indexOfObject:self]==NSNotFound) {
// back button was pressed. We know this is true because self is no longer
// in the navigation stack.
[self.view.window endEditing:YES];
}
[super viewWillDisappear:animated];
}