Reputation: 529
For some reason, I can't seem to get my compose email to work under swift 2.0. I did worked fine under swift version 1, but no longer work on version 2. Any suggestion? Thanks.
import UIKit
import MessageUI
class EmailViewController: UITableViewController, MFMailComposeViewControllerDelegate, UITextFieldDelegate {
let userDefaults = NSUserDefaults.standardUserDefaults()
@IBOutlet weak var name: UITextField!
@IBOutlet weak var phone: UITextField!
@IBOutlet weak var email: UITextField!
@IBAction func SendEmailButton(sender: AnyObject) {
let fields: [UITextField] = [name, phone, email]
let messageBody = "Name:\(name.text)\nPhone:\(phone.text)\nEmail:\(email.text)"
let emailTitle = "Interface Information"
let toRecipents = [""]
let mc: MFMailComposeViewController = MFMailComposeViewController()
mc.mailComposeDelegate = self
mc.setSubject(emailTitle)
mc.setMessageBody(messageBody, isHTML: false)
mc.setToRecipients(toRecipents)
self.presentViewController(mc, animated: true, completion: nil)
}
override func viewDidAppear(animated: Bool) {
name.text = userDefaults.stringForKey("name")
phone.text = userDefaults.stringForKey("phone")
email.text = userDefaults.stringForKey("email")
}
}
Upvotes: 0
Views: 51
Reputation: 38833
You seem to have some issues with your textfields. I would probably guess that the outlets does not work and you could test to drag them again. I created a sample project for you that you can check how I have done it with your code and see if it helps you. You can download the code from here.
Upvotes: 1