【发布时间】:2019-01-30 20:56:21
【问题描述】:
我对使用 swift 进行编程非常陌生,并尝试构建一个将日期/时间从 UIDatePicker 发送到定义的电子邮件地址的应用程序。我尝试将 UIDatePicker 的输出转换为字符串。我如何在我的电子邮件中得到这个?
我在“mailComposerVC.setMessageBody(strDate”上收到一个错误
到目前为止我的代码是:
@IBOutlet weak var mijnDatumTijd: UIDatePicker!
@IBAction func datumTIjd(_ sender: UIDatePicker){let dateFormatter = DateFormatter()
dateFormatter.dateStyle = DateFormatter.Style.short
dateFormatter.timeStyle = DateFormatter.Style.short
let strDate = dateFormatter.string(from: mijnDatumTijd.date)
}
var email: String = ""
@IBOutlet weak var Identifier: UITextField!
@IBAction func buttonClick(sender: UIButton) {
//getting input from Text Field
email = Identifier.text!
}
@IBAction func send(_ sender: UIButton) {
_ = configuredMailComposeViewController()
}
func configuredMailComposeViewController() -> MFMailComposeViewController {
let mailComposerVC = MFMailComposeViewController()
mailComposerVC.mailComposeDelegate = self as? MFMailComposeViewControllerDelegate // Extremely important to set the --mailComposeDelegate-- property, NOT the --delegate-- property
mailComposerVC.setToRecipients(["example@email.com"])
mailComposerVC.setSubject("Sending you an in-app e-mail...")
mailComposerVC.setMessageBody(strDate, isHTML: false)
return mailComposerVC
【问题讨论】:
-
错误信息是什么? (把它放在你的问题中,而不是在评论中)。
-
什么是
strDate?
标签: ios swift mfmailcomposeviewcontroller