电子邮件格式化不会从tableView获取信息

时间:2016-03-21 16:01:01

标签: ios swift uitableview mfmailcomposer

我正在尝试让我的应用发送一封电子邮件,其中包含在View控制器中收集的所有数据

这是我的代码

func sendemail() {
    let formatter = NSDateFormatter()
    formatter.dateStyle = .MediumStyle
    formatter.timeStyle = .FullStyle
    let dateString = formatter.stringFromDate(datePicker.date)

    var emailtext = NSLocalizedString("Pilot name : ", comment: "");
    emailtext += String(pilotsTextField.text)
    emailtext += "<br />";
    emailtext = NSLocalizedString("Aicraft : C-", comment: "");
    emailtext += String(acRegTextField.text)
    emailtext += "<br />";
    emailtext += "<br />";
    emailtext = NSLocalizedString("Passengers :", comment: "");
    emailtext += "<br />";
    for (var i=0 ; i < passengers.count; i++) {
                   let passenger = passengers[i]
        emailtext = "Name: \(passenger.paxName)"
        emailtext += "<br />";
        emailtext = "Name: \(passenger.paxWeight)"
        emailtext += "<br />";
        emailtext = "Name: \(passenger.paxEmergencyName)"
        emailtext += "<br />";
        emailtext = "Name: \(passenger.paxEmergencyPhone)"
        emailtext += "<br />";
        emailtext = "Name: \(passenger.paxDestinationComments)"
        emailtext += "<br />";
        emailtext += "<br />";
    }
    emailtext += "<br />";
    emailtext += "Date and Departure time : ";
    emailtext += dateString;
    emailtext += "<br />";
    emailtext += NSLocalizedString("Canadian Helicopters Limited", comment: "");

    let mailVC = MFMailComposeViewController()
    mailVC.mailComposeDelegate = self
    mailVC.setToRecipients(["manifests@canadianhelicopters.com"])
    mailVC.setSubject(NSLocalizedString("Manifest from \(pilotsTextField.text) for \(acRegTextField.text)", comment: "email"))
    mailVC.setMessageBody(("\(emailtext)"), isHTML: true)

    self.presentViewController(mailVC, animated:true, completion:nil)
}

但是,循环中找到的所有内容都不会填充电子邮件表单...

任何想法???

1 个答案:

答案 0 :(得分:1)

func sendemail() {
    let formatter = NSDateFormatter()
    formatter.dateStyle = .MediumStyle
    formatter.timeStyle = .FullStyle
    let dateString = formatter.stringFromDate(datePicker.date)

    var emailtext = NSLocalizedString("Pilot name : ", comment: "");
    emailtext += String(pilotsTextField.text)
    emailtext += "<br />";
    emailtext += NSLocalizedString("Aicraft : C-", comment: "");
    emailtext += String(acRegTextField.text)
    emailtext += "<br />";
    emailtext += "<br />";
    emailtext += NSLocalizedString("Passengers :", comment: "");
    emailtext += "<br />";
    for (var i=0 ; i < passengers.count; i++) {
                   let passenger = passengers[i]
        emailtext += "Name: \(passenger.paxName)"
        emailtext += "<br />";
        emailtext += "Name: \(passenger.paxWeight)"
        emailtext += "<br />";
        emailtext += "Name: \(passenger.paxEmergencyName)"
        emailtext += "<br />";
        emailtext += "Name: \(passenger.paxEmergencyPhone)"
        emailtext += "<br />";
        emailtext += "Name: \(passenger.paxDestinationComments)"
        emailtext += "<br />";
        emailtext += "<br />";
    }
    emailtext += "<br />";
    emailtext += "Date and Departure time : ";
    emailtext += dateString;
    emailtext += "<br />";
    emailtext += NSLocalizedString("Canadian Helicopters Limited", comment: "");

    let mailVC = MFMailComposeViewController()
    mailVC.mailComposeDelegate = self
    mailVC.setToRecipients(["manifests@canadianhelicopters.com"])
    mailVC.setSubject(NSLocalizedString("Manifest from \(pilotsTextField.text) for \(acRegTextField.text)", comment: "email"))
    mailVC.setMessageBody(emailtext, isHTML: true)

    self.presentViewController(mailVC, animated:true, completion:nil)
}