Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITextField no longer reloads keyboardType after reloadInputViews call

Tags:

xcode6

ios8

In iOS 7, I could change the keyboard type while it is the firstResponder (on the fly):

if (textField.text.length > 2) {

    textField.keyboardType = UIKeyboardTypeNumbersAndPunctuation;
}
else
{
    textField.keyboardType = UIKeyboardTypeDefault;
}

[textField reloadInputViews];

// (Omitting some efficiency stuff to keep example to bare bones)

This no longer works under Xcode 6/iOS 8. The documentations mostly reflect changes regarding custom keyboard.

Using resign/become first responder is (still) working:

[textField resignFirstResponder];

// Make keyboard change

[textField becomeFirstResponder];

But it just feels like an overkill. It's tearing and rebuilding a wall, just to change a picture on it.

There is a related post here: UITextView does not seem to implement reloadInputViews

But it seems that the solution (in a comment) is "apparently declaring it as a UITextView instead of a UIResponder affects how it behaves during runtime. ... and it works now"

In my case it is a UITextField, and I tried to cast to UITextView just in case. No go.

I'll mention again that it is working well under iOS7 / Xcode5.

I don't really know if this is a 'beta' issue with Xcode 6, or a design change in iOS 8.

like image 772
bauerMusic Avatar asked Jul 03 '14 06:07

bauerMusic


1 Answers

I found that this works when the textfield is first responder:

[self.textField reloadInputViews];
[self.textField setText:@" "];
[self.textField setText:@""];
like image 131
pickwick Avatar answered Sep 27 '22 17:09

pickwick