如何在swift中对UIAlertController的文本字段进行自动完成

时间:2016-06-22 07:45:02

标签: swift swift2

我想为textfield做自动填充,例如电子邮件。

我在互联网上搜索过,我没有找到swift版本,很多演示使用tableview来显示结果。

我的问题是:

1:我不想用tableview来显示结果,我想像safari那样做,当你写一些东西时,结果是灰色的并完成句子。

2:我想为UIAlertController的文本字段执行自动填充功能。我UIAlertController文本字段的代码是

let ac = UIAlertController(title: "Enter e-mail", message: nil, preferredStyle: .Alert)
            ac.addTextFieldWithConfigurationHandler(nil)

            let submitAction = UIAlertAction(title: "Send", style: .Default) { [unowned self, ac] (action: UIAlertAction!) in
                self.dismissKeyboard()

}

2 个答案:

答案 0 :(得分:0)

如果文本框是通过storyboard添加的,则单击然后单击文本框

然后选择AtrributeInspector - >改变校正 - >是

这将用于处理自动更正

谢谢,

答案 1 :(得分:0)

我使用Swift 5解决了这个问题:

let alert = UIAlertController(title: "Alert Title", message: "...", preferredStyle: .alert)
alert.addTextField { (textfield) in
    textfield.text = "default value"
    textfield.autocorrectionType = .yes
}