Setting UITextView's editable to NO always resigns FirstResponder. Can be avoided? - ios

My app basically lets you send a piece of text. When the user taps send, I would like to disable the text view which contains the text so the user can't edit it anymore as the text is being sent. It seems though that setting either enableUserInteraction or editable to NO always resigns the first responder (basically the keyboard is dismissed) which is a behavior I don't want. I want to keep the keyboard displayed. Is there anyway around this? Thanks in advance.

While I don't really understand why you think it's a good idea to keep the keyboard on screen if there's nothing to edit, you can achieve this by having a hidden UITextField and making that first responder.

If the UITextView's delegate method textView:shouldChangeTextInRange:replacementText: returns NO, its contents will not be changed.

Related

iOS why calling removing the first responder from a uitextield affects the keyboard?

Okay i have two urtext fields, when i click on one of them, the keyboard shows.
now i have another button so when the user clicks it, i want to hide the keyboard (okay it is a stupid design, but i am just learning).
when the user clicks that button, what i do in code is calling the resignfirstresponder method on both of the ui text fields like this:
self.firstuitextfield.resignFirstResponder()
self.seconduitextfield.resignFirstResponder()
and by some maject the keyboard disappear, my question is why is that?
I just removed the first responder from them, and that means, according to this question, they will not receive the messages first anymore. How can this make the keyboard disappear? and bty who now becomes the first responder?
Nobody is the first responder! That's what's happening! And if they're no responders, then the keyboard hides! Pretty nifty, right? But if you want one line of code to do this, try self.view.endediting(true), instead.

iOS Custom keyboard can't return focus to app's textfield

I'm working on a custom keyboard for iOS which will have its own search field (similarly implemented by PopKey).
My keyboard's textfield is able to take the focus with becomeFirstResponder and I'm able to give it up by using resignFirstResponder. However after I resign focus, the host app has a difficult time retaking focus despite touching the form. The app's textfield will still show the text cursor blinking.
Any ideas? Thanks
The solution is a hack, as of right now you can't really give the host app its focus back.
Subclass a UITextField and on its delegate implement
textFieldShouldBeginEditing by returning NO.
Add a BOOL property isSelected that gets set to YES in touchesBegan (not to be confused with the default selected property)
In your keyboard's keyPressed method, if searchField.isSelected, manipulate the searchField.text. Else, manipulate textDocumentProxy like normal.
Add a clear button and method that wipes searchField.text and searchField.isSelected, allowing any further keystrokes to return to the textDocumentProxy
Add an animation that replicates the blinking type cursor

Swap out a custom inputView for the standard keyboard in iOS

I have a custom inputView for a particular textfield, and it works well. However, I cannot discern how to dismiss the view and get the regular keyboard back. (I have a SWAP button right next to the TextField.) I tried setting the textfield's inputView to nil, but that did nothing.
I do not need a full custom keyboard, but I need more than an Accessory view above the keyboard, which is why I am trying this route. I need about 20 custom buttons in addition to the regular keyboard, and I do not like the idea of a huge Accessory view taking up so much space.
I also would rather not require the user to initially install a full custom keyboard before being able to use the app.
Thank you very much for any suggestions.
I think you will probably have to do this:
Call resignFirstResponder on the UITextField
After the animation finishes, set your inputView to nil
Call becomeFirstResponder on the text field
The keyboard animation duration is sent in the userInfo dictionary on the keyboard presentation notifications.
In addition to the accepted answer, you can use reloadInputViews() (and this is less likely to suffer any animation glitches resulting from the resignFirstResponder, becomeFirstResponder calls):
yourTextField.inputView = nil;
yourTextField.reloadInputViews();
Here's more info in the Apple's Docs.

Prevent iOS keyboard from disappearing / reappearing between UITextFields?

I've got a form with some UITextField instances, and I've set up an accessory view to flip back and forth between them as you fill in the form. The ugliness is that the keyboard slides away, then immediately slides back for the next form.
Since it's going to remain there, is there a way to get it to simply stay up throughout the whole form, rather than this ugly/silly gone/back behaviour? I may be doing something wrong programmatically, I'm telling fields to resignFirstResponder before the new one does becomeFirstResponder – is that the cause?
You don't need to called resignFirstResponder when switching between text fields, iOS will handle this for you when calling becomeFirstResponder on another object. You just need to call resignFirstResponder if/when you want to hide the keyboard, say at the end of the form.
Yes, that is the cause. You can just call becomeFirstResponder without calling resignFirstResponder and you'll get what you want
When you select other UITextField than automatically the last UITextField resign first responder so you should not resignFirstResponder every time. Just resign when you done with UITextField or user click on the UIView.

Keep keyboard always on top & visible

I have view with a text field, an image and a few buttons.
I want to make sure the keyboard is displayed and is on top when the view is displayed
AND
I want to make sure it doesn't go away after I type something in to the text field and submit it.
I called [txtField becomeFirstResponder] with viewdidload and the keyboard is appearing by default but with a tiny delay after the view is displayed.
Also the becomefirstresponder doesn't help after I have my text field submitted.
Thanks in advance for your help!
Also the becomefirstresponder doesn't help after I have my text field submitted.
That part makes no sense. By default, a text field does not dismiss the keyboard unless you dismiss it with endEditing: or resignFirstResponder. If the keyboard is going away, you must be making it go away. So don't and it won't.
EDIT: And indeed, your comment later reveals the answer: you've hooked up the didEndOnExit control event from the text field. Well, that causes the keyboard to be dismissed when the user presses the Done button! So you are effectively hitting yourself in the face and then complaining that someone is hitting you in the face.
So the solution, obviously, is don't hook up the didEndOnExit control event (to anything). Instead, just give the text field a delegate and use the delegate messages to learn what the user is doing. None of those have any automatic behavior with regard to the keyboard, so the keyboard won't be dismissed automatically. For example, to learn when the user is typing, use textField:shouldChangeCharactersInRange:replacementString:. To learn when the user has hit the Done button, use textFieldShouldReturn:. And so on.

Resources