Im using MFMailComposeViewController to send emails, but after you sent an email I would like to show the email and time it was done on a tableview. How can I do that?
My table code is basic
//This is empty, just to populate the empty table for now
var sentEmails = [String]()
//Number of Sections
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
//Number of Rows
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return sentEmails.count
}
//Cell Configuration
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier, forIndexPath: indexPath)
let row = indexPath.row
cell.textLabel?.text = sentEmails[row] //Email here?
cell.detailTextLabel?.text = "time stamp"//maybe?
return cell
}
This is my code for the mail
func contactPicker(picker: CNContactPickerViewController, didSelectContactProperty contactProperty: CNContactProperty) {
//Checks if composer can sent email
if MFMailComposeViewController.canSendMail() {
let mail = MFMailComposeViewController()
mail.mailComposeDelegate = self
//Add the email to the recipient field
if let emailAddress = contactProperty.value as? String {
mail.setToRecipients([emailAddress])
}
//Dismisses the current view and presents the mail composer view
self.dismissViewControllerAnimated(true, completion: {() -> Void in
self.presentViewController(mail, animated: true, completion: nil)
})
} else {
print("send error")
}
}
//Dismiss Buttons for Mail Composer
func mailComposeController(controller:MFMailComposeViewController, didFinishWithResult result:MFMailComposeResult, error:NSError?) {
switch result {
case MFMailComposeResultCancelled:
print("Mail Cancelled")
case MFMailComposeResultSaved:
print("Mail Saved")
case MFMailComposeResultSent:
print("Mail Sent")
case MFMailComposeResultFailed:
print("Mail sent failure: \(error)")
default:
break
}
controller.dismissViewControllerAnimated(true, completion: nil)
}
How can I get the sent email and time to show on my table? Thank you in advance.