【发布时间】:2016-08-23 20:32:12
【问题描述】:
我正在使用 MFMailComposeViewController 发送电子邮件,但在您发送电子邮件后,我想在表格视图上显示电子邮件和时间。我该怎么做?
我的表代码是基本的
//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
}
这是我的邮件代码
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)
}
我怎样才能获得发送的电子邮件和时间显示在我的桌子上?先感谢您。
【问题讨论】:
标签: swift tableview mfmailcomposer