0
votes

I am experiencing issues where the text I have input into a UITextField is disappearing whenever it is resigned as the first responder. When you tap back into the text field, the text re-appears. The UITextField subclass has nothing in it apart from a slight rounding to the corners. I will be adding more at a later date. Has anyone experienced issues like this before?

Here is my code. Like I said there is nothing in this subclass apart from the rounding of the corners. I will be putting code to add padding to the textfield later.

Code

import UIKit

class EVTextField: UITextField
{
  override func layoutSubviews()
  {
    layer.cornerRadius = 2.0
  }
}

Step by step guide to replicate

  1. Tap on UITextField.
  2. Enter text.
  3. Either dismiss keyboard or tap into next UITextField.
  4. Text seems to disappear in previously resigned UItextField.

Video Example Weirdtextfield

2
As i can see the text stays there but, probably its text color after didendediting of uitextfield ? - Aragunz
@Aragunz No the colour is still black, I have checked when debugging the view hierarchy - Rhuari Glen
show text field delegate code?people can understand - karthikeyan
In the image above it looks like TEst and yyyy are there when u switch textfields ? - Aragunz
@Aragunz Yes, when I switch back to the textfield the text re-appears which is fine. But it disappears when I resign the responder of that textfield - Rhuari Glen

2 Answers

2
votes

Found the problem, I had forgotten to call super.layoutSubviews() when rounding the corners of my UITextFields. Stupid mistake.

0
votes

Please try this:

if (self.emailTextField.isFirstResponder) {
    [self.emailTextField resignFirstResponder];
}

if (self.passwordTextField.isFirstResponder) {
    [self.passwordTextField resignFirstResponder];
}