gpt4 book ai didi

ios - Swift 从滑动菜单中关闭邮件 Controller

转载 作者:行者123 更新时间:2023-11-28 08:30:15 24 4
gpt4 key购买 nike

我在使用 MFMailComposer 时遇到了问题。我已经使用示例 Swift Code 遵循了 iOS 开发人员指南.

我还查看了本网站上的以下类似问题:

swift - dismissing mail view controller from Sprite Kit

MFMailComposeViewController in Swift does not dismiss

链接的框架和库:MessagesUI.framework

import MessageUI

class FHCLLeftMenuViewController: FHBaseViewController,UITableViewDelegate,UITableViewDataSource,MFMailComposeViewControllerDelegate

当我点击应用左侧滑动菜单中的“支持”文本时,“邮件”应用出现,我撰写了一封电子邮件并单击“发送”。该电子邮件出现在我的收件箱中,但 Controller 在发送邮件后并未自动关闭。当我尝试删除草稿并且必须关闭应用程序并重新启动时,也会发生这种情况。

        case kFHCLMenuTagSupport:
//PT DashBoard

if !MFMailComposeViewController.canSendMail() {
print("Mail services are not available")
return
}

let composeVC = MFMailComposeViewController()
composeVC.mailComposeDelegate = self

// Configure the fields of the interface.
composeVC.setToRecipients(["support@example.com"])
composeVC.setSubject("Client Support")
composeVC.setMessageBody("Some text here.", isHTML: false)



// Present the view controller modally.
self.presentViewController(composeVC, animated: true, completion: nil)

func mailComposeController(controller: MFMailComposeViewController,
didFinishWithResult result: MFMailComposeResult, error: NSError?) {
// Check the result or perform other tasks.

// Dismiss the mail compose view controller.
self.dismissViewControllerAnimated(true, completion: nil)

}
break

我也尝试过这种变体以返回到应用程序的主仪表板,结果相同:

     case kFHCLMenuTagSupport:
//PT DashBoard
let storyboard = UIStoryboard(name: "Client", bundle: nil)

// Create View Controllers
let mainPage:FHClientDashBoardViewController = storyboard.instantiateViewControllerWithIdentifier("FHClientDashBoardViewController") as! FHClientDashBoardViewController
let mainPageNav = UINavigationController(rootViewController: mainPage)



if !MFMailComposeViewController.canSendMail() {
print("Mail services are not available")
return
}

let composeVC = MFMailComposeViewController()
composeVC.mailComposeDelegate = self

// Configure the fields of the interface.
composeVC.setToRecipients(["support@example.com"])
composeVC.setSubject("Client Support")
composeVC.setMessageBody("Some text here.", isHTML: false)



// Present the view controller modally.
self.presentViewController(composeVC, animated: true, completion: nil)

func mailComposeController(controller: MFMailComposeViewController,
didFinishWithResult result: MFMailComposeResult, error: NSError?) {
// Check the result or perform other tasks.

// Dismiss the mail compose view controller.
// self.dismissViewControllerAnimated(true, completion: nil)
self.mm_drawerController.setCenterViewController(mainPageNav, withCloseAnimation: true, completion: nil)
}

break

任何帮助将不胜感激。

最佳答案

dismissViewControllerAnimated(_:completion:) 函数关闭调用该函数的 View Controller 。在这种情况下,由于您在 self 上调用它,它会尝试关闭 FHCLLeftMenuViewController。这可以通过在 MFMailComposeViewController 上调用 dismissViewControllerAnimated(_:completion:) 来轻松解决。

为此,只需将 mailComposeController(controller:didFinishWithResult:error:) 函数替换为以下内容(它在 Apple 自己的文档中也以这种方式出现):

func mailComposeController(controller: MFMailComposeViewController, didFinishWithResult result: MFMailComposeResult, error: NSError?) {
// Check the result or perform other tasks.

// Dismiss the mail compose view controller.
controller.dismissViewControllerAnimated(true, completion: nil)
}

关于ios - Swift 从滑动菜单中关闭邮件 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39002848/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com