iosnsnotificationcenteripad-mini

"UIKeyboardWillShowNotification" cannot be received on iPad mini


I added following code to viewWillAppear:animated in main view controller.

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

And, I implemented this method in same class,

- (void)showKeyboard:(NSNotification *)notification
{
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"Keyboard will appear." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [alert show];
}

Main view controller has a UITextField object.

In iPad2 (iOS 5.0), an alert view appears when it was focused. However, in iPad mini (iOS 6.0), nothing appears except a software keyboard.

I want to make iPad mini be same behavior as iPad2.

Thanks,


Solution

  • As of iOS 3.2, UIKeyboardWillHideNotification and UIKeyboardWillShowNotification are no longer fired when switching between two text fields. Basically, the notifications only fire if the keyboard is actually shown or hidden. Use UIKeyboardDidShowNotification instead.

        if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 3.2) {
            [[NSNotificationCenter defaultCenter] addObserver:self 
                                                     selector:@selector(keyboardDidShow:) 
                                                         name:UIKeyboardDidShowNotification 
                                                       object:nil];     
        } else {
            [[NSNotificationCenter defaultCenter] addObserver:self 
                                                     selector:@selector(keyboardWillShow:) 
                                                         name:UIKeyboardWillShowNotification 
                                                       object:nil];