How to set Custom keyboard specific to only a UIte

2019-07-26 14:15发布

问题:

How to set Custom keyboard specific to only a UITextField? When I am changing using this method, all the keyboards in my application are changed to this new custom keyboard. I added:

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

in a UIViewController. But after going to that UIView, keyboards in other UIViewControllers also look like new custom keyboard. How can i limit the custom keyboard to only one UIView? Please help me. Thanks in advance.

回答1:

UITextField* textField;
UIView* customKeyboard;


textField.inputView = customKeyboard;

Similar thread: iPad custom Keyboard GUI



回答2:

If you subclassed UITextView (as that tutorial shows), then all instances of that subclass will use the toolbar with a dismiss button.

If you don't want the toolbar, then don't use the subclass, just use the original UITextView.



回答3:

You can try checking for the textfield that you want on the textFieldShouldBeginEditing like so:

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
    if (textField == YOUR_DESIRED_TEXTFIELD) {
        [self openCustomKeyboard];
    }
    return YES;
}


回答4:

My problem was once am loading custom keyboard, it remains everywhere in other UIviews of application. So i checked existence of UIToolbar in other UIkeyboard subviews and removed . Now its working fine..

    for(UIView* keyboardToolbar in [keyboard subviews]){
        if([[keyboardToolbar description] hasPrefix:@"<UIToolbar"] == YES)
            {
                [keyboardToolbar removeFromSuperview];      
            }
    }