每当我按"取消"然后"删除草稿",邮件作曲家不会被解雇。我得到的错误是"线程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)
}
}
答案 0 :(得分:0)
对于那些不知道的人,EXC_BAD_ACCESS意味着它试图访问不再存在的内存中的内容。在按钮点击后,我错误地创建了EmailComposer()对象,因此它超出了范围。所以这个:
let emailComposer = EmailComposer()
...应该在这里创建,例如:
class TableViewController: UITableViewController {
let emailComposer = EmailComposer()