为什么不能关闭 MFMailComposerViewController?
Why can't won't the MFMailComposerViewController be dismissed?
每当我按 "Cancel" 然后按 "Delete Draft" 时,邮件编辑器都不会被关闭。我得到的错误是 "Thread 1: EXC_BAD_ACCESS (code=1, address=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)
}
}
对于那些不知道的人,EXC_BAD_ACCESS 意味着它试图访问内存中不再存在的东西。我 错误地 在点击按钮后创建了 EmailComposer() 对象,因此它超出了范围。所以这个:
let emailComposer = EmailComposer()
...应该是在这里创建的,例如:
class TableViewController: UITableViewController {
let emailComposer = EmailComposer()
每当我按 "Cancel" 然后按 "Delete Draft" 时,邮件编辑器都不会被关闭。我得到的错误是 "Thread 1: EXC_BAD_ACCESS (code=1, address=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)
}
}
对于那些不知道的人,EXC_BAD_ACCESS 意味着它试图访问内存中不再存在的东西。我 错误地 在点击按钮后创建了 EmailComposer() 对象,因此它超出了范围。所以这个:
let emailComposer = EmailComposer()
...应该是在这里创建的,例如:
class TableViewController: UITableViewController {
let emailComposer = EmailComposer()