我正在尝试将我发送的电子邮件的电子邮件和时间保存到表格视图中。电子邮件发送正常,但每当我单击发送按钮时,我都会收到此错误(错误:在展开可选值时意外发现 nil)。我不确定我的代码中的错误在哪里。
发送按钮的代码:
//SentEmails Array
var sentEmails = [emailObject]()
//Default email
var sentEmailTo = "email@email.com"
//Dismiss Buttons for Mail Composer
func mailComposeController(controller:MFMailComposeViewController, didFinishWithResult result:MFMailComposeResult, error:NSError?) {
//Check for errors
if let error = error {
print("Error: \(error)")
return
}
switch result {
case MFMailComposeResultCancelled:
print("Mail Cancelled")
case MFMailComposeResultSaved:
print("Mail Saved")
case MFMailComposeResultSent:
//Save information to tableview
let emailSent = emailObject(sentTo: sentEmailTo, timeSent: NSDate())
sentEmails.append(emailSent)
tableView.reloadData()
print("Mail Sent")
case MFMailComposeResultFailed:
print("Mail sent failure: \(error)")
default:
break
}
controller.dismissViewControllerAnimated(true, completion: nil)
}
我的手机号码:
//Cell Configuration
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier, forIndexPath: indexPath)
let row = indexPath.row
let dateFormat = NSDateFormatter()
dateFormat.dateStyle = .ShortStyle
dateFormat.timeStyle = .ShortStyle
cell.textLabel?.text = sentEmails[row].sentTo
cell.detailTextLabel?.text = dateFormat.stringFromDate(sentEmails[row].timeSent)
return cell
}
错误:
*不知道我能做到这一点,这是错误的详细信息: