我有这个代码,但我不知道如何在UIAlertView中显示文本字段.

var altMessage = UIAlertController(title: "Warning", message: "This is Alert Message", preferredStyle: UIAlertControllerStyle.Alert)
altMessage.addAction(UIAlertAction(title: "Done", style: UIAlertActionStyle.Default, handler: nil))
self.presentViewController(altMessage, animated: true, completion: nil)

我有textfield的代码,如何在UIAlerView中显示

var my:UITextField = UITextField(frame: CGRectMake(0, 0, 10, 10))

我还try 了以下代码:

var alert = UIAlertView()
alert.title = "Enter Input"
alert.addButtonWithTitle("Done")
alert.alertViewStyle = UIAlertViewStyle.PlainTextInput
alert.addButtonWithTitle("Cancel")
alert.show()

当我指定AlertStyle纯文本时,它会显示一个带有默认占位符"Login"的文本字段..我想改变这一点,我想展示一个十进制键盘.我还想处理用户在文本字段中输入的值.有人能帮我吗?

推荐答案

您可以通过以下方式访问文本字段:

let textField = alert.textFieldAtIndex(0)

然后,要更改占位符文本:

textField.placeholder = "Foo!"

和键盘类型:

textField.keyboardType = ...

Swift相关问答推荐

编写Swift字符串的属性包装时遇到问题

当计数大于索引时,索引超出范围崩溃

仅当单击UIButton时才调用计时器函数

Result类型的初始值设定项失败?

如何增加 NSStatusBar 图像大小?

使用 @resultBuilder 的通用 buildList 函数

如何根据 DatePicker 中选定的日期实现 TabView 页面切换?

Swift UI中视图上的值未更新

在 Swift 5.7 中使用协议作为类型时什么时候需要写 `any`

SwiftUI:列表背景为空列表时为黑色

如何在 SceneKit 上制作毛玻璃效果

TextField 键入未完成

如何避免从模块导入函数

获取 SwiftUI 中 Binding 的值更改更新

What is "SwiftPM.SPMRepositoryError error 5"?

Swift - 迭代 struct 对象时如何对其进行变异

自定义 Google 登录按钮 - iOS

Swift中方法的弃用和其他属性,如何?

将 UIImage 剪成圆形

将 [String] 存储在 NSUserDefaults 中