【问题标题】:UITextField text disappearing while typing [closed]打字时UITextField文本消失[关闭]
【发布时间】:2016-03-11 05:50:31
【问题描述】:

在 UITextField 文本上观察到的奇怪行为消失了,

步骤: 在 UITextField 中输入文本并单击主页按钮。 打开另一个应用程序(应用程序)并单击主页按钮。 然后打开第一个应用程序,文本中的 UITextField 消失了。 在 iPhone 6s 版本 9.2.1 中观察到问题。但在模拟器中完美工作。

【问题讨论】:

  • 您是否将输入的文本存储在任何地方?分配给文本文件?
  • 在我的情况下无法重现,检查 viewwillappear 中是否有任何代码使文本框为空或 applicationdidenterforeground。
  • 也无法重现。也许您可以创建一个断点并在调试模式下运行您的应用程序以重试。
  • stackoverflow.com/questions/22494543/… 我指的是同样的问题!

标签: ios objective-c user-interface uitextfield


【解决方案1】:

您可以在自定义响应程序中覆盖此方法以更新对象的状态或执行一些操作,例如突出显示选择。如果你重写了这个方法,你必须在你的实现中调用 super。

自定义类应该类似于:

class CustomSecureTextField: UITextField { 
    override func becomeFirstResponder() -> Bool {
        super.becomeFirstResponder()
         //if !isSecureTextEntry {
         //  return true 
         //} 
         if let currentText = text {  
             insertText(currentText)
         } 
         return true
    } 
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-21
    • 1970-01-01
    • 1970-01-01
    • 2017-08-23
    • 1970-01-01
    • 2012-05-08
    相关资源
    最近更新 更多