【问题标题】:Why can't won't the MFMailComposerViewController be dismissed?为什么不能关闭 MFMailComposeViewController?
【发布时间】:2016-03-08 02:06:02
【问题描述】:

每当我按“取消”然后“删除草稿”时,邮件编写器都不会被解雇。我得到的错误是“线程 1:EXC_BAD_ACCESS(代码=1,地址=0x40363380)”

在我的 TableViewController 我有:

@IBAction func mailButton(sender: AnyObject) {
    let emailComposer = EmailComposer()
    if email != "" {
        print(email)
        if emailComposer.canSendMail() {
            emailComposer.setRecipient(email)
            let configuredMailComposeViewController = emailComposer.configuredMailComposeViewController()
            presentViewController(configuredMailComposeViewController, animated: true, completion: nil)
        }
    } else {
        let alertController = UIAlertController(title: "Sorry!", message: "No email found for this contact", preferredStyle: .Alert)
        alertController.addAction(UIAlertAction(title: "OK", style: .Default, handler: { (action) -> Void in
            //do nothing
        }))
         self.presentViewController(alertController, animated: true, completion:nil)
    }

}

【问题讨论】:

    标签: swift mfmailcomposeviewcontroller


    【解决方案1】:

    对于那些不知道的人,EXC_BAD_ACCESS 意味着它试图访问内存中不再存在的东西。我错误地在点击按钮后创建了 EmailComposer() 对象,因此它超出了范围。所以这个:

    let emailComposer = EmailComposer()
    

    ...应该在这里创建,例如:

    class TableViewController: UITableViewController {
    
    let emailComposer = EmailComposer()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多