邮件表单由几个文本字段组成

时间:2016-05-16 16:44:53

标签: ios email textfield

我对xcode中的app制作非常新,我在制作应用时遇到了一个小问题。 所以我想要做的是,我想要一个包含多个文本字段的页面,当您按下按钮时,文本字段中的所有信息都将作为邮件发送。 我有一切工作,一件事。发送邮件时,所有信息都在一行,我希望每个文本字段中的信息都在邮件的sepperat行。 我对任何帮助表示赞赏,对不起任何拼写错误,我来自丹麦。 :)

代码:

@IBOutlet var text3: UITextField!
@IBOutlet var text2: UITextField!
@IBOutlet var text1: UITextField!

    @IBAction func sendEmail(sender: AnyObject) {     let mailComposeViewController = configuredMailComposeViewController()
    if MFMailComposeViewController.canSendMail() {
    self.presentViewController(mailComposeViewController, animated: true, completion: nil)
    } else {
    self.showSendMailErrorAlert()
    }
}
func configuredMailComposeViewController() -> MFMailComposeViewController {
    let mailComposerVC = MFMailComposeViewController()
    mailComposerVC.mailComposeDelegate = self // Extremely important to set the --mailComposeDelegate-- property, NOT the --delegate-- property
    let messageBody = text1.text!+text2.text!+text3.text!
    mailComposerVC.setToRecipients(["wastepin@hotmail.com"])
    mailComposerVC.setSubject("New Dumpster")
    mailComposerVC.setMessageBody(messageBody, isHTML: false)
    return mailComposerVC
}
func showSendMailErrorAlert() {
    let sendMailErrorAlert = UIAlertView(title: "Could Not Send Email", message: "Your device could not send e-mail.  Please check e-mail configuration and try again.", delegate: self, cancelButtonTitle: "OK")
    sendMailErrorAlert.show()
}
// MARK: MFMailComposeViewControllerDelegate
func mailComposeController(controller: MFMailComposeViewController!, didFinishWithResult result: MFMailComposeResult, error: NSError!) {
    controller.dismissViewControllerAnimated(true, completion: nil)
}

图片:

input page (picture)

mail page (picture)

1 个答案:

答案 0 :(得分:0)

你需要的只是

let messageBody = text1.text!+"\n"+text2.text!+"\n"+text3.text!

Larme说的正是如此:)