swift - MailComposeViewController 错误 : unexpectedly found nil

标签 swift null runtime-error optional-values

我正在尝试将我发送的电子邮件的电子邮件地址和时间保存到表格 View 中。电子邮件发送正常,但每当我单击发送按钮时,我都会收到此错误(错误:在展开可选值时意外发现 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)
}

我的手 secret 码:

//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
}

错误:

enter image description here

*不知道我能做到这一点哈哈,这是错误的详细信息:

enter image description here

最佳答案

当崩溃发生时,您可以按1行, enter image description here

它将显示有关崩溃发生位置的更多信息(在 ViewController 文件中)。你能张贴截图吗?

抱歉,我无法发布图片作为对该问题的评论。一旦我们知道更多,将编辑答案。

关于swift - MailComposeViewController 错误 : unexpectedly found nil,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39128629/

相关文章:

swift - 如何更新 ARKit 中的 pointOfView

ios - 使用 NSURL 的结果填充 UIView

python - 用于在空字段上选择的 Peewee 语法

c++ - 将指向 null 的指针设置为分配的内存吗?

javascript - 理解 null 对象与 0 作为数字

c - 在c中使用指针反转字符串

java - UVA在线判断运行时错误

swift - 如何创建一个具有固定顶行内容和数据库中其余行的表

swift - 如何仅在一个 View Controller 上更改导航栏属性

javascript - Reactjs 类型错误 : Cannot read property 'style' of undefined