UIKeyboardWillShowNotification不适用于iOS> 6.1

时间:2013-05-22 16:43:11

标签: ios objective-c ipad ios6.1

初始化部分:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) 
                                                 name:UIKeyboardWillShowNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) 
                                                 name:UIKeyboardWillHideNotification object:nil]; 

某种方法:

- (void) keyboardWillShow:(NSNotification*) aNotification {
// TO DO 
}

Dealloc部分:

[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];

因此在iOS 6.1中显示视图后没有调用keyboardWillShow ... 在iOS 6.0中,此代码完美运行。

1 个答案:

答案 0 :(得分:2)

“init部分”是被添加的观察者?例如,如果您的视图控制器来自故事板,那么它应该在- (id)initWithCoder:(NSCoder *)decoder

但我的建议是在viewWillAppear中设置观察者,并在viewWillDisappear中删除它们。这样设置和拆卸是“平衡的”,只有在视图控制器的内容可见时才会激活。