UIKeyboard通知处理程序触发了3次

时间:2015-04-01 02:48:18

标签: ios uikeyboard

我的代码:

-(void)viewWillAppear:(BOOL)animated {
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleKeyboard:) name:UIKeyboardWillChangeFrameNotification object:nil];
}

-(void)viewWillDisappear:(BOOL)animated {
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

-(void)handleKeyboard:(NSNotification*)notification {
  NSLog(@"triggered");
}

请参阅:

enter image description here

消失的处理程序正常触发一次,但出现时则触发3次。这是iOS错误吗?

1 个答案:

答案 0 :(得分:0)

可能对您的问题没有帮助,但您需要致电[super viewWill…进行覆盖。

-(void)viewWillAppear:(BOOL)animated

-(void)viewWillDisappear:(BOOL)animated

来自文档。

  

如果覆盖此方法,则必须在某个时刻调用super   你的实施。