Swift 中的 MFMailComposeViewController 不会关闭 [英] MFMailComposeViewController in Swift does not dismiss

查看:15
本文介绍了Swift 中的 MFMailComposeViewController 不会关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是示例代码:

import UIKit
import MessageUI

class ViewController: UIViewController, MFMailComposeViewControllerDelegate {

@IBAction func showEmail(sender : AnyObject) {
    var emailTitle = "Test Email"
    var messageBody = "This is a test email body"
    var toRecipents = ["a.nakhimov@gmail.com"]
    var mc: MFMailComposeViewController = MFMailComposeViewController()
    mc.mailComposeDelegate = self
    mc.setSubject(emailTitle)
    mc.setMessageBody(messageBody, isHTML: false)
    mc.setToRecipients(toRecipents)

    self.presentViewController(mc, animated: true, completion: nil)
}

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

func mailComposeController(controller:MFMailComposeViewController, didFinishWithResult result:MFMailComposeResult, error:NSError) {
    switch result.value {
    case MFMailComposeResultCancelled.value:
        NSLog("Mail cancelled")
    case MFMailComposeResultSaved.value:
        NSLog("Mail saved")
    case MFMailComposeResultSent.value:
        NSLog("Mail sent")
    case MFMailComposeResultFailed.value:
        NSLog("Mail sent failure: %@", [error.localizedDescription])
    default:
        break
    }
    self.dismissModalViewControllerAnimated(true)
    // self.dismissViewControllerAnimated(true, completion: nil)
}

}

当我按下按钮时,函数 showEmail 被执行并出现发送电子邮件的表单.如果我单击发送",则一切正常 - 发送邮件,然后执行 ma​​ilComposeController 函数.NSLog 显示标签已发送邮件",然后重新出现初始屏幕.

When I push the button, the function showEmail is executed and appears the form for send email. If I click "Send", then everything works fine - mail is sent, then the function mailComposeController is executed. NSLog displays the label "Mail sent" and the initial screen reappears.

如果我在发送邮件的对话框中,点击取消"按钮,然后对话框不会消失,功能ma​​ilComposeController不起作用,两个按钮-发送"和取消",变成灰色并保持不变.

If I'm in the dialog box of send mail, click "Cancel" button, then dialogue does not disappear, function mailComposeController does not work, two buttons - "Send" and "Cancel", becoming gray color and so it stays.

怎么了?

推荐答案

似乎是 iOS 8 中的 bug.同样的问题在 Objective-C 中也存在.

Seems to be bug in iOS 8. Same problem exist in Objective-C also.

这篇关于Swift 中的 MFMailComposeViewController 不会关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆