views:

322

answers:

2

Hi

I have a custom keyboard I want to show when the user taps a UITextField. But at the same time I want to show the cursor in the textfield. If if return a NO for canBecomeFirstResponder, it doesn't show the default keyboard but doesn't show the cursor either.

Can someone please help me out?

Thanks.

A: 

I'm not sure of the point, but why not just use a UILabel with the same contents of the text field and decorated to look like your text field with a cursor in it. Swap it out for a UITextField when you want input.

Andiih
i don't want the default keyboard to show up. And how do I show a cursor in a UILabel?
sherry
Ah, so are you saying that your custom keyboard is not a keyboard as such, its just a set of buttons so you want to fake the whole thing ?
Andiih
A: 

Register as keyboard notification observer (e.g. in the view controller where you want to hide the keyboard):-

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

Put in the hideKeyboard: function:-

-(void)hideKeyboard:(NSNotification *)notification {

    for (UIWindow *keyboardWindow in [[UIApplication sharedApplication] windows]) {
        for (UIView *keyboard in [keyboardWindow subviews]) {
            if([[keyboard description] hasPrefix:@"<UIKeyboard"] == YES) {

                keyboard.alpha = 0;
            }
        }
    }
}

(Thanks to luvieere in this post for showing me how to get the keyboard)

happy pig
Doesn't work for me in iOS4. The method gets called but no view has a prefix of UIKeyboard
alku83