【问题标题】:mail form made from several text fields由多个文本字段组成的邮件表单
【发布时间】:2016-05-17 01:00:31
【问题描述】:

我对在 xcode 中制作应用程序非常陌生,我在制作应用程序时遇到了一个小问题。 所以我想要做的是,我想要一个包含多个文本字段的页面,当您按下按钮时,来自文本字段的所有信息都作为邮件发送。 我有一切工作,除了一件事。发送邮件时,所有信息都在一行上,我希望每个文本字段中的信息在邮件中的单独行上。 我从丹麦获得任何帮助,对任何拼写错误感到抱歉。 :)

代码:

@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)

【问题讨论】:

  • let messageBody = text1.text!+text2.text!+text3.text!,您只需附加它们,例如在它们之间添加一个“\n”。
  • 所以应该是:text1.text!\n+text2.text!\n+text3.text!还是?
  • 谢谢你@Larme 你是男人! :D
  • @peter-boesen : 不确定我是否应该得到这些积分决定发布答案哥们:)
  • @Sandeep Bhandari 我只是不知道如何给他,因为他把它作为评论而不是答案,如果可以的话,我会把它们给他。 ://

标签: ios email textfield


【解决方案1】:

你只需要

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

正是拉尔姆所说的:)

【讨论】:

    猜你喜欢
    • 2016-04-27
    • 2020-01-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多