switching inputview for uitextfield

13,061

Solution 1

Things have changed quite a bit, since I wrote this answer way back in 2012, the recommended approach as mentioned by @yoooriii is:

myTextField.inputView = nil
myTextField.reloadInputViews()

Solution 2

Use this one instead:

-reloadInputViews (UIResponder)

Solution 3

The solution that worked for me to switch back to the default keyboard when the textField was already the first responder (keyboard on screen) was set his inputView to nil than call reloadInputViews like this:

textField.inputView = nil;
[textField reloadInputViews];

Hope this helps.

Solution 4

You need to create a inputView that is not nil. As Apple help says:

If the value in this property is nil, the text field displays the standard system keyboard when it becomes first responder. Assigning a custom view to this property causes that view to be presented instead.

The default value of this property is nil.

To implement it:

Create a property like apple says:

@property(readwrite, strong) UIView *inputView;

Initiate it:

self.inputView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];

Assign it to your textField or textView's inputView:

[textView setInputView:self.inputView];

Reload all inputViews:

[textView reloadInputViews];

You can do them in textViewDidBeginEditing:

- (void)textViewDidBeginEditing:(UITextView *)textView {
      self.inputView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
      [textView setInputView:self.inputView];
      [textView reloadInputViews];
}
Share:
13,061
pa12
Author by

pa12

Updated on June 04, 2022

Comments

  • pa12
    pa12 almost 2 years

    I am making a custom input view for my textfield in textFieldDidBeginEditing method using

    textField.inputView =wView;
    

    There is button using which I want to get back the keyboard instead of my custom input view. Any idea how to do that.

    If there is no other go I wanted to try with resigning textfield as first responder and make it first responder again. But this would really complicate my project. I wanted to know if there is any other way.

  • pa12
    pa12 over 11 years
    So the only solution is to resign the textfield as first responder?
  • John Dvorak
    John Dvorak about 11 years
    A usage sample would be nice. Also, please review the formatting guide.
  • cnotethegr8
    cnotethegr8 over 9 years
    @JanDvorak, use it like this. self.textView.inputView = nil; [self.textView reloadInputViews];