views:

156

answers:

1

Hello,

I'm using a trick to overlay the keyboard with my own. Basically I add some buttons as Subviews to the Keyboard. This is how I find the UIView of the keyboard:

UIWindow* tempWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:1];
UIView* keyboard;
for(UIView* potentialKeyboard in tempWindow.subviews)
    // if the real keyboard-view is found, remember it.
    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 3.2) {
        if([[potentialKeyboard description] hasPrefix:@"<UIPeripheralHost"] == YES)
            keyboard = potentialKeyboard;
        }
        else {
            if([[potentialKeyboard description] hasPrefix:@"<UIKeyboard"] == YES)
                keyboard = potentialKeyboard;
    }

This method is called by the UIKeyboardDidShowNotification. I'd rather have it called by UIKeyboardWillShowNotification, since the "Did" version shows after the original keyboard is shown to the user. But if I use the same procedure as above it produces a EXC_BAD_ACCESS error. Apparently the keyboard's view is not found properly.

Now my question: Is there any way to access the keyboard's UIView at the time UIKeyboardWillShowNotification is fired.

Thanks in advance

A: 

I added simply used this [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow) name:UIKeyboardWillShowNotification object:nil];

and

- (void)keyboardWillShow { [self performSelector:@selector(addHideKeyboardButtonToKeyboard) withObject:nil afterDelay:0]; } .

This is called when keyboard is going to appear.

Simon
It worked, although I've got a feeling that this could cause trouble. It's just a feelig, but I think delay:0 might call the selector too fast... But well, it works.In the end I had to use both: keyboardWillShow with the delay to have the keyboard appear overlayed and the keyboardDidShow to have it stay like that. Somehow the overlay disappeared once the view was fully loaded.But anyway it works. Thanks.
Bujtor
When using performSelector:afterDelay: the main thread is handling the call, and because the uikeyboard animation is called by the main thread, you have to wait for it to finish, therefor, use a performSelector:afterDelay:
Simon