gpt4 book ai didi

ios - 不调用 NSNotification keyBoardWillShow 和 keyboardWillHide

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:34:08 26 4
gpt4 key购买 nike

我有一个带有自定义 View 的 xib 文件,上面有很多文本字段 subview 。我已经将每个文本字段的委托(delegate)设置为文件所有者,并且能够成功地使用 texfield 委托(delegate)方法。但不幸的是,键盘通知方法 keyboardWillShow: 和 keyboardWillHide: 根本没有被调用。

我在 textfieldShouldBeginEditing 添加了观察者,并在 textFieldDidEndEditing 移除了观察者。

这是我的代码片段:

添加观察者

-(void) textFieldShouldBeginEditing : (UITextField *) textField{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
}

移除观察者

-(void) textFieldDidEndEditing : (UITextField *) textField{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
}

//通知的方法

- (void)keyboardWillShow:(NSNotification *)notification
{
NSLog(@"Here");
}

- (void)keyboardWillHide:(NSNotification *)notification
{
NSLog(@"There");
}

//keyboardwillShow 和 keyboardWillHide 中的任何一个都不会被调用。

如果有人可以帮助我找出我的代码问题或我可能遗漏的任何底层问题,那就太好了。

最佳答案

当您通过编辑 textView 显示键盘时,您正在添加一个观察者。它不会调用,因为键盘已经显示。您应该在 viewWillAppear 上添加观察者并移除 viewWillDisappear 方法。

关于ios - 不调用 NSNotification keyBoardWillShow 和 keyboardWillHide,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42029826/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com