2016-05-16 58 views
2

即時通訊應用程序製作非常新,我在製作應用程序時遇到了一個小問題。 所以我想要做的是,我想要一個包含多個文本字段的頁面,當您按下按鈕時,文本字段中的所有信息都將作爲郵件發送。 我有一切工作,免除一件事。郵件發送時,所有信息都在一行中,我希望每個文本字段中的信息位於郵件中的分隔線上。 我appriciate任何幫助,並抱歉任何拼寫錯誤,即時消息來自丹麥。 :)由幾個文本字段組成的郵件表

代碼:

@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(["[email protected]"]) 
    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)

+2

'let messageBody = text1.text!+ text2.text!+ text3.text!',你只需追加它們,例如在它們之間添加一個「\ n」。 – Larme

+0

所以它應該是:text1.text!\ n + text2.text!\ n + text3.text!要麼? –

+0

謝謝@Larme你是男人! :D –

回答

0

所有你需要的是

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

正是Larme所說的:)

+0

非常感謝你們,這是當然! :d –

相關問題