代码之家  ›  专栏  ›  技术社区  ›  Elye

如何将自定义文本域添加到警报?

  •  0
  • Elye  · 技术社区  · 6 年前

    我可以将文本域添加到我的警报中,如下所示 alert.addTextField()

            let alert = UIAlertController(title: "Title", message: "Subtitle", preferredStyle: UIAlertController.Style.alert)
            alert.addTextField()
            alert.addAction(UIAlertAction(title: "Ok", style: UIAlertAction.Style.default, handler: { _ in
                print(alert.textFields?[0].text ?? "")
            }))
            alert.addAction(UIAlertAction(title: "Cancel", style: UIAlertAction.Style.default, handler: nil))
            self.present(alert, animated: true, completion: nil)
    

    https://stackoverflow.com/a/29783546/3286489 ,如何将其添加到我的警报中(而不是仅使用通用文本字段)?

    1 回复  |  直到 6 年前
        1
  •  1
  •   mattsven    6 年前

    圣道

    Apple提供的API不允许您使用 UITextField . 但是,它允许您自定义 :

    alert.addTextField { textField in
        // customize text field
    }
    

    您必须尝试移植 CurrencyView 输入框 .

    邪道

    免责声明:这是个坏主意。使用供应商api的方式并不是为了降低代码和应用程序的稳定性。

    现在我们已经解决了这个问题:您还可以直接向默认值添加一个视图 . 你必须在原始文件上禁用交互/编辑 输入框 ,但请确保它只转到自定义文本字段。

    真正地 想走到黑暗的一面,你可以 强迫你 当前视图