【问题标题】:Swift -- UITextField is not showing keyboard and I cannot edit itSwift——UITextField 没有显示键盘,我无法编辑它
【发布时间】:2020-11-18 22:20:45
【问题描述】:

我正在向另一个 UIWindow 之上的 UIWindow 添加一个 UITextField,但我无法编辑 UITextField。此外,当我从一个 UITextField 更改为另一个时,我收到以下警告 rejected resignFirstResponder when being removed from hierarchy。我添加了部分代码。我添加了inputNote.delegate = self 并调用了这些方法,但是当我尝试输入时没有任何反应。感谢您的时间和回答。

calc = UIWindow(frame: cFrame)
calc.windowLevel = UIWindow.Level.alert
calc.rootViewController = UIViewController()
calc.makeKeyAndVisible()
calc.isUserInteractionEnabled = true

self.view.addSubview(calc)



panel = UIWindow(frame: pFrame)
panel.windowLevel = UIWindow.Level.alert
panel.rootViewController = UIViewController()
panel.makeKeyAndVisible()

calc.addSubview(panel)



let inputNote = UITextField()
inputNote.isUserInteractionEnabled = true
inputNote.clearsOnBeginEditing = true
inputNote.clearButtonMode = .whileEditing
inputNote.frame = CGRect(x: 15, y: 150, width: width - 5, height: 35)
inputNote.placeholder = "Note"

panel.addSubview(inputNote)

【问题讨论】:

  • 您是在模拟器还是物理设备上运行您的项目?
  • 我在模拟器中运行它。
  • 这样做:Shift + Command + K 告诉我!
  • 它不起作用,我已经尝试了所有这些。我认为这与我正在创建的 Windows 有关。
  • 你解决过这个问题吗?不使用情节提要并将窗口设置为root肯定是个问题。我目前正在努力解决这个问题

标签: ios swift uitextfield


【解决方案1】:

添加以下行以启用 UITextField - inputNote.isEnabled = true

【讨论】:

    猜你喜欢
    • 2015-10-06
    • 1970-01-01
    • 2020-12-31
    • 1970-01-01
    • 2013-03-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多