iOS: Text disappearing from subclassed UITextfield when responder resigns
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
Video Example
Found the problem, I had forgotten to call super.layoutSubviews()
when rounding the corners of my UITextFields. Stupid mistake.
请试试这个:
if (self.emailTextField.isFirstResponder) {
[self.emailTextField resignFirstResponder];
}
if (self.passwordTextField.isFirstResponder) {
[self.passwordTextField resignFirstResponder];
}
链接地址: http://www.djcxy.com/p/44312.html
上一篇: 如何在文本字段和视图之间切换第一个响应者