UITextField clear glitch - text highlights, selection carets appear - ios

I'm seeing a glitch in a UITextField when you tap on the clear button (the little X). Immediately before the text disappears, the selection carets appear (the vertical lines you move to select text) and then the text highlights as if it were selected. This only happens for an instant -- the highlight and carets flash on then immediately go away. The text does, in fact, clear -- the problem is that it's a distracting visual glitch.
Has anyone seen this?
Related question: Is there a notification posted or delegate method called somewhere when text is highlighted? I could use that to detect the flash. But, I can't seem to find anything...

I also experienced this issue, on iOS8. My class is observing UITextFieldTextDidChangeNotification. Although I didn't find the explanation of WHY it's happening I found the following UITextField delegate fixed it for me:
- (BOOL)textFieldShouldClear:(UITextField *)textField {
textField.text = nil;
return YES;
}
Just nil the textfield text on 'clear' - takes care of the visual glitch.

Related

UITextField not responding to touches or will not become active

I added a UITextField to my storyboard:
#property (weak, nonatomic) IBOutlet UITextField *nameField;
And it was working fine at first, but had some constraint issues which caused the view to not build correctly on an iPhone 5. So I messed with some of the constraints to get it to display correctly and now the keyboard never comes up/the UITextField refuses to respond to touches OR become active.
I tried setting a UITapGestureRecognizer to the nameField, didn't work.
I made sure there were no views blocking it (checked on the view debugger, and then explicitly called [self.view bringSubviewToFront:self.nameField]; in viewDidAppear)
I tried [self.nameField setUserInteractionEnabled:YES]; as well because why not.
So then I went to the storyboard, clicked on the text field and under the connection tab on the right side menu I looked at "Sent Events" and hooked up Touch Up Inside to an IBAction method:
- (IBAction)beginNameEdit:(id)sender {
NSLog(#"Edit begin");
BOOL accepted = [self.nameField becomeFirstResponder];
if (accepted) {
NSLog(#"accepted");
}
}
Nothing happens, (Edit begin did not print). (I touched up inside the boundary as well for sure, but whatever)
So then I hooked up Touch Down to the same exact IBAction.
This time, I started getting 'Edit begin' to print but the call to become first responder did nothing despite accepted actually getting printed (which means that according to Apple, the text field accepted first responder status)
I can't seem to make my textField active and so it's forever stuck on showing the placeholder text... It makes no sense, especially because I would be shocked if playing with some of the auto layout constraints could have any sort of effect.
Any suggestions?
Ok, and in classic the-answer-is-the-last-thing-you'd-expect fashion:
I was using the simulator to test the app. Turns out the keyboard doesn't always come up when you're using the simulator because it auto-detects the fact you have an ACTUAL keyboard on the computer you are using. So instead of a keyboard coming up on the simulator it was silently becoming the first responder and waiting for me to type something on my computer's keyboard.
Why the keyboard was coming up earlier and not now, I have no clue. But I'll leave this up in case anyone else comes across this issue.

HKTextview emoji detection

I'm having an issue. I am using the Hakawai framework in an app so that I can have mention support (#username).
The issue I've run into is that the textfield I am using is not registering the case where there is no text and a user types an emoji into the textview. As we are using HKWTextView, I believe the textViewShouldChangeTextInRange delegate method is never called, even if implemented. The only replacement I can think to use is :
- (void)textView:(HKWTextView *)textView didChangeAttributedTextTo:(NSAttributedString *)newText
originalText:(NSAttributedString *)originalText
originalRange:(NSRange)originalRange;
in HKWTextView, but that's still not picking up on emojis being typed in when no other text has.
The functionality I would like is:
- Text view is empty
- user types in anything, emoji included
- textview width shortens, "Post" button appears.
Right now, typing emojis into the empty text view will not make the post button appear. However, it's worth mentioning that once the emojis are typed in, if there is more than one, deleting one of them WILL make the post button appear. I'm at a bit of a loss here.
I found the answer to this - It turns out that HKWTextView does some rewiring of the UITextView delegate methods that are fired. Try handling the input in the UITextView delegate method textViewDidChangeSelection. That method will be fired when an emoji is typed.

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: ..

UITextField not getting keyboard input

I'm having troubles entering text into an UITextField under a SVProgressHUD (Basically an UIView with a full-screen transparent UIWindow and some UIView subviews showing text and a custom-drawn progress bar).
My problem is that the UITextField displays the blinking cursor and the keyboard shows, but when I tap a key, nothing is entered into the text field.
I only see that the cursor's blinking interrupts just like normal.
Interestingly enough, the back (delete) key works (it really deletes the last letter in the UITextView), but not any other key.
I'm using iOS 6.
Any help would be highly appreciated.
EDIT:
The same UITextField works fine when there's no SVProgressHUD displayed. This makes me think it has something to do with the first responder, but I have already tried calling resignFirstResponder on every window and subview of the SVProgressHUD and it still does not work.
I finally found the problem:
SVProgressHUD calls makeKeyAndVisible when it's initialized, because it wants to receive keyboard notifications for repositioning. I looked up what the "Key Window" actually is and found out:
...The key window responds to user input...
Now, as the UIWindow of the SVProgressHUD was the keyWindow, my other window, which contained the UITextField did not get the user input.
I finally call makeKeyWindow on the AppDelegate's window and everything is working fine.
I hope this helps anyone with similar problems.
Call resignFirstResponder() to dismiss the keyboard before showing SVProgressHUD.
Have you implemented the method....
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
...to filter out any unwanted characters? If so, perhaps it's being a little overzealous with the filtering?
For me this is worked.
I did changes in my textfield delegate method then it worked.
if ([textField isEqual:selectBankName])
{
return No;
}
else if ([textField isEqual:enterAmountTextfield])
{
return YES;
}
return NO;
}
set delegate for textfield
Make sure textfield userInteraction is Enabled.And
Finally Please check your textfield delegate method.

clearButton not working in UITextEditField

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.

Resources