clearButton not working in UITextEditField - ios

This is one of those "it was working a while ago" troubleshooting efforts.
I'm working on the document preview view controller, in which is a scroll view, which itself contains subclasses of UIView that represent each document. I'm modeling this pretty closely to how Keynote handles its document preview, except I build my scroll view horizontally and with paging. But the standard user experience is present: Long press on a document icon causes all document icons to start jiggling, nab bar has + button and Edit button, etc.
The issue at hand is that when you tap on the name of a document, I hide all the others, move the one being edited front and center, build a new text edit field, add it as a subview atop the real name label, and set it as first responder; but the
[editNameTextField setClearButtonMode:UITextFieldViewModeWhileEditing];
while correctly showing in the edit field is not taking any action when the user taps on the clear button.
I can't figure out what I may have done to cause this to not work -- it had been!
My first thought was that somehow my instance of this subclass is no longer the delegate for this text edit field. To try and confirm/deny that, I usurped a tap on the image view of the document preview to compare the delegate property to self, and it passes.
if (editNameTextField) {
NSLog(#"editNameTextField is still active");
if ([editNameTextField.delegate isEqual:self]) {
NSLog(#"we're still the delegate for the editNameTextField");
}
}
Editing the text within the edit field works fine. Pressing the Return/Done key correctly sends the delegate message textFieldShouldReturn:
While investigating this I implemented the delegate method textFieldShouldClear: just to write a log message if the method gets called (and return YES of course). It never gets called.
My next thought was that perhaps a subview had covered up the area where the clear button sits. So I implemented textFieldShouldBeginEditing: and used the opportunity to bring my the text field to the front. That didn't change anything either. I set a debugger breakpoint there to play a sound when it was called, and it got called, so I know my text edit field is frontmost.
I have only one troubleshooting strategy remaining: Go backwards through snap shots until it starts working again. Before doing that I thought I'd see if any of the more experienced folks out here have any suggestions of what to try next.

Where are you adding the textfield? As a subview of the scrollView? If you added the textfield and it is out of bounds of its parent view it won't receive any touches.
You can try and not call becomeFirstResponder and see if clicking it will show keyboard. Another possible error might be that the parent view of the UITextField has userInteractionEnabled = NO.
Without seeing more code I'm afraid I can not offer more solutions.

Related

When set UITextField as FirstResponder programmatically, cause some weird actions on text editing

I have a UITextField with custom keyboard, basically like a calculator. I would like my keyboard show up by default, so i used [self.topInputTextField becomeFirstResponder]; in viewDidLoad, I think that's very common usage. However, it causes some very weird actions on my textfield.
When i set my textfield as the first responder in viewDidLoad, and every time after i done editing, the text will jump, and when i click another text field and and click the first text field again, the texts in the first text field sometimes shift down and disappear, but sometimes not. I feel it's very hard to describe, so i recorded a GIF image for it.
And the reason, that I am sure [self.topInputTextField becomeFirstResponder]; causing the issue, is when i comment that line of code out, everything back to normal. here is the GIF after i comment out that line:
that's vert strange to me, between 2 GIF file, the only change i did is comment out that line of code. I couldn't find any solution on SE. Any idea would be very appreciated.
Edit:
One more thing is I tried to change font, and font sizes, they all have similar strange behaviors.
*Edit 2:**
here is how i set up my textfield,i didn't do anything fancy
Try calling the keyboard in viewDidAppear, this method gets called after viewDidLoad. I assume it's because you should only call the keyboard on a loaded view that has appeared to the user, so if you call it before the view actually appears it will cause unexpected behaviour.
viewDidLoad is too early for calling this, the UI hasn't worked out which size your screen is, or even which orientation your device is in. It isn't yet a UI really... Try it in willAppearAnimated: ..

UIPageViewController bug with UITextField and keyboard showing

So I'm trying to find a workaround for this bizarre bug:
http://www.screencast.com/t/UqvVn8ccodEV
Basically I have a UIPageViewController with sub view controllers (obviously). Once I add a text field, it does this weird thing where if you scroll it and then click a text field, it randomly moves to another page. None of the delegates get called, and the keyboard moves up and down again.
Seems like the same thing as here: clicking/typing on UITextField increments UIPageViewController instead of displaying keyboard
Also seems to be recorded here: http://openradar.appspot.com/13315308
Can't figure out what the hell this would be, or a way around it.
Edit
Here is a skeleton version (pulled from the linked question):
https://www.dropbox.com/s/6l5efem3wque7li/pageScroll.zip?v=1mci
Scroll one page, then hit the textfield. Only happens the first time around.
Check this voodoo out: Embed your UITextField within a UIScrollView. I tried it on the project you referred to and it worked.
I guess it has something to do with changing the responder chain that messes things up.

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.

UITextField not receiving touch event

I have a UITextField in a complex view hierarchy. The text field is in a UIView with label and textfield, say, labelfield.
I can type text there.
There is info button on top right corner. When tap on Info, a modal view controller is loaded. When coming back from the modal view controller, the UITextField becomes unresponsive. I cannt type anything there. The labelfiedl is drawn and shown in the screen.
Interesting thing is that, if I press the ok button, and alert is shown and then the textfield becomes active. Also, on top of the view, there is some text with user interaction enable, if I tap and try to select the text and after that the textfield becomes active. Seems I have to do some other activity/touch on the super view, then the text field becomes active.
Why not on the first case it receive any touch event? I tried with textField.enabled, becomesFirstResponder, setNeedsDisplay in the viewDidApper method, nothing works.
Try the following...
Make sure that the super view to which the text field is added as subview large enough to contain text field(ie make sure that no part of text field is out side the superview. check this for all views).
Make sure that there is no view above textfield.use bringSubViewToFront: method.
Try to enable use interaction after a delay
Hope any of the above fix will solve your problem

iOS keyboard flickers when switching view controllers

I have a registration form and I want to have the keyboard always on top.
The way I'm doing it now, is that when the user moves between view controllers, in viewDidLoad, the first UITextField becomes the first responder.
The problem is that the keyboard flickers (disappears and then appears again) when the user moves between view controllers.
Also, related to this: I have a form with a few uitextfields. When the user presses next it goes to the next uitextfield using becomefirstresponder. When the user is in the last textfield, the keyboard button becomes "Done". Then, when the user presses it, if there's an error with the last field, it should get the focus (calls becomeFirstResponder) but that doesn't happen (nothing get's the focus and the keyboard goes down). All the other fields get the focus fine, just this last field doesn't. I've tried about everything: switching to other textfields and back. The problem is that done automatically removes the keyboard.
You should have made two separate questions for this.
First, your flickering:
I'm guessing you're using a UINavigationController. You can add an invisible UITextField somewhere in the UINavigationController, which you give focus before you switch to a new ViewController. Then, when the new ViewController has appeared (viewDidAppear), set the focus to the first textField as you want.
However, the entire approach is kind of hackey and I don't recommend you use it. Instead, try using several views in a scrollView, of which you change the offset when you move to the new view. This will also solve the flickering.
Second, losing firstResponder status on Done:
The done button is specifically there to indicate exactly that which it says; Done. Pressing this assumes the user is finished and that no text is left to type, thus dismissing the keyboard.
If you really want to keep the Done button, then try the following;
Allow the user to dismiss the keyboard.
Upon dismissal, check for the error in the last field.
If there is an error, instead of calling [lastField becomeFirstResponder], try [self performSelector:#selector(thisSelectorWillCallFirstResponder) withObject:nil afterDelay:1.0].
In the method thisSelectorWillCallFirstResponder call [lastField becomeFirstResponder].
This will give time for the keyboard to disappear, before making it pop up again, so it doesn't interfere with the becomeFirstResponder call.
Another method would be to not use a Done button, but instead use the return key. You can intercept return anytime with the delegate method textFieldShouldReturn:. There you can handle any error checking, without causing the textField to lose its focus.

Resources