13

Here is a video of the phenomena: http://youtu.be/c0TP8YVF9TE

As the video shows, the value in exampleTextView.text is not lost. Its just hidden every other keystroke.

Solutions tried: I do not set the exampleTextView.text value to something during the program, except after the return key is pressed (and commenting that line out changes nothing).

I have set:

self.exampleTextView.clearsOnBeginEditing=NO;
self.exampleTextView.clearsContextBeforeDrawing=NO;
self.exampleTextView.clearsOnInsertion=NO;

Edit: Here is my code: https://gist.github.com/andrewschreiber/6970283

Andrew Schreiber
  • 14,344
  • 6
  • 46
  • 53

6 Answers6

31

I had almost the same problem. Sometimes the text was disappearing.

I solved it after changing the position of the UITextField in the view hierarchy in the xib file.

enter image description here

SbClx
  • 326
  • 3
  • 4
11

I was facing the same problem. My solution was to remove [_textField becomeFirstResponder] from the - (void)viewWillAppear:(BOOL)animated method. This bug only occurs if the viewcontroller was presented modally.

René Fischer
  • 468
  • 3
  • 10
2

Moving the UITextField's becomeFirstResponder from viewWillAppear to viewWillLayoutSubviews fixed this for my case. I also made sure to add resignFirstResponder on the UITextField to the actions that were dismissing the view (which was presented modally).

0

Try to use all the Delegate method of UITextField . and please let me know what are you trying to do with Done Button clicked , only set the text of anything else or if you share all the code with me then i can help you

Please replace your textFieldShouldReturn method with my method and also implementing the textFieldShouldBeginEditing method in your code and its working fine

 -(BOOL) textFieldShouldReturn:(UITextField *) textField {

          [textField resignFirstResponder];
    }


- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {


    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.5];


    [UIView commitAnimations];

    return YES;


}
nivritgupta
  • 1,966
  • 2
  • 20
  • 38
  • 1
    I tried this, both with 'return YES' and 'return NO' in textFieldShouldReturn. That did not solve the problem, but gave me some ideas to try. – Andrew Schreiber Oct 15 '13 at 21:17
0

Solved the problem.

On my storyboard, I switched the text from 'Plain' to 'Attributed' then back to 'Plain' again.

Andrew Schreiber
  • 14,344
  • 6
  • 46
  • 53
0

@SbClx 's solution works for me, but I have another workaround that also works: set the background of the UITextField to any UIImage you like.

After some trial and error, I found that the bug disappears when I set the borderStyle of UITextField to UITextBorderStyleRoundedRect, which is unfortunately not what I wanted, I want a simple white background.

The documentation of UITextField.borderStyle states that: If the value is set to the UITextBorderStyleRoundedRect style, the custom background image associated with the text field is ignored. So I guess background image might have something to do with the bug too.

ssynhtn
  • 1,307
  • 12
  • 18