16

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.

2
  • Try textField.inputView = nil;
    – user529758
    Oct 16, 2012 at 16:30
  • I tried it absolutely no change.
    – pa12
    Oct 16, 2012 at 16:36

5 Answers 5

36

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()
1
  • So the only solution is to resign the textfield as first responder?
    – pa12
    Oct 16, 2012 at 18:30
31

Use this one instead:

-reloadInputViews (UIResponder)
2
  • A usage sample would be nice. Also, please review the formatting guide. Apr 24, 2013 at 21:11
  • 2
    @JanDvorak, use it like this. self.textView.inputView = nil; [self.textView reloadInputViews]; Oct 21, 2014 at 6:40
11

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.

2

If you're using datePicker inside textfield which has a toolbar in it, do this following thing to get back your input view.

Swift 3, 4, 5 :

 textField.inputView = nil
 textField.inputAccessoryView = nil
 textField.reloadInputViews()
1

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.