How to set Custom keyboard specific to only a UItextfield

允我心安 提交于 2019-12-11 09:06:51

问题


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];      
            }
    }


来源:https://stackoverflow.com/questions/3265363/how-to-set-custom-keyboard-specific-to-only-a-uitextfield

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!