2016-03-08 71 views
0

每当我按“取消”,然后“删除草稿”,邮件作曲家将不会被解雇。我得到的错误是 “主题1:EXC_BAD_ACCESS(代码= 1,地址= 0x40363380)”为什么MFMailComposerViewController不能被解除?

在我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) 
    } 

} 

回答

0

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

let emailComposer = EmailComposer() 

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

class TableViewController: UITableViewController { 

let emailComposer = EmailComposer()