为什么不能关闭 MFMailComposerViewController?



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

在我的表视图控制器中,我有:

@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)
    }
}

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

let emailComposer = EmailComposer()

。应该在此处创建,例如:

class TableViewController: UITableViewController {
let emailComposer = EmailComposer()

相关内容

  • 没有找到相关文章

最新更新