在按下按钮后显示来自文本字段的输入的警报

时间:2017-07-12 20:53:47

标签: ios swift uialertcontroller

编辑:感谢此处有人的帮助。更新了代码以反映正在运行的内容。

为学校制作基础项目。 "紧急联系"各种清单。

4个文本字段,名称,关系,电话号码和电子邮件。按下按钮然后将此数据传输到标签,然后清除文本字段。我想要一个警告弹出说明Textfield或Label的数据是什么。

我能找到的就是如何在警报中添加文本字段。我不想要这个。我只想在按下按钮时显示警告文本字段中输入的内容。

目前声明如下消息:

"Please be aware you are setting contact information for alerts to be 
sent to Contact 4."

但我希望它显示

"Please be aware you are setting contact information for alerts to be 
sent to Contact 4.
EMAIL@EMAIL.COM
407-123-4567"

" email@email.com"和" 407-123-4567"将是文本框中的任何用途。

屏幕截图示例代码按预期工作。 信息输入文本字段。当按下相应的联系人按钮时,信息将相应地传递给标签,然后在警报中弹出。 First image Second image

 @IBAction func contact4Button(_ sender: Any) {


    // Setting the information for text fields
    c4N = nameFieldtxt.text!
    c4Namelbl.text = "\(c4N!)"

    c4R = relationshipFieldtxt.text!
    c4Relationshiplbl.text = "\(c4R!)"

    c4C = contactFieldtxt.text!
    c4Contactlbl.text = "\(c4C!)"

    c4E = emailFieldtxt.text!
    c4Emaillbl.text = "\(c4E!)"

    c4lbl.text = "Contact 4"
    nameFieldtxt.text=""
    relationshipFieldtxt.text=""
    contactFieldtxt.text=""
    emailFieldtxt.text=""

    // Alert for the warning of contact alerts
    let alertController = UIAlertController(title: "P.H.A.B.S.", message: 
    "Please be aware you are setting contact information for alerts to be sent 
    to \(c4lbl.text!) \n \n \(c4N!) \n \(c4C!) \n \(c4E!) \n", preferredStyle: .alert)


    let defaultAction = UIAlertAction(title: "Dismiss", style: .default, handler: nil)
    alertController.addAction(defaultAction)

    present(alertController, animated: true, completion: nil)

}

0 个答案:

没有答案