Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/121.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 键盘隐藏通知多次调用_Ios_Objective C_Iphone - Fatal编程技术网

Ios 键盘隐藏通知多次调用

Ios 键盘隐藏通知多次调用,ios,objective-c,iphone,Ios,Objective C,Iphone,先生,我正在隐藏键盘 -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { [self.view endEditing:YES]; } 他们工作得很好。但当我们第二次编辑textView时。 [[NSNotificationCenter defaultCenter]addObserver:自选择器:@selector(keyboardWillBeHidden:)名称:UIKeyboardWillHideNot

先生,我正在隐藏键盘

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    [self.view endEditing:YES];
}
他们工作得很好。但当我们第二次编辑textView时。
[[NSNotificationCenter defaultCenter]addObserver:自选择器:@selector(keyboardWillBeHidden:)名称:UIKeyboardWillHideNotification对象:nil]多次呼叫。他们在键盘上执行我的代码5-6次。是他们在textview开始编辑时不调用的任何方式

- (void)textViewDidBeginEditing:(UITextView *)textView
{

    if ([textView.text isEqualToString:@"Type your message Here..."]) {
        textView.text = @"";
        textView.textColor = [UIColor grayColor]; //optional
    }

    [self scrollToBottomAnimated:YES];
  }
- (void)scrollToBottomAnimated:(BOOL)animated
{
    NSInteger rows = [tableViews numberOfRowsInSection:0];
    if(rows > 0) {
        [tableViews scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:rows - 1 inSection:0]
                          atScrollPosition:UITableViewScrollPositionBottom
                                  animated:animated];
    }
}

这取决于您在NSNotificationCenter注册键盘通知的位置和次数

如果要在视图中添加观察者,则将显示,在视图中删除观察者将消失

如果要在viewdidload中添加观察者,请在dealloc调用中删除观察者

请尝试更改您注册通知的位置。要确保只有可视控制器是接收通知的控制器,请在vieWillAppear中注册通知,并删除ViewWillEnglish中的通知


这也将解决多次调用代码的问题。

在添加通知中心的位置尝试此操作