2016-08-17 48 views
1

我在使用MFMailComposer時遇到了問題。我使用示例Swift Code按照iOS開發人員指南。Swift Dismiss來自幻燈片菜單的郵件控制器

我也採取了看看本網站上的以下類似的問題:

swift - dismissing mail view controller from Sprite Kit

MFMailComposeViewController in Swift does not dismiss

鏈接框架&庫:MessagesUI.framework

import MessageUI 

class FHCLLeftMenuViewController: FHBaseViewController,UITableViewDelegate,UITableViewDataSource,MFMailComposeViewControllerDelegate 

當我點擊我的應用程序的左側滑動菜單中的支持文本,郵件應用程序出現我寫了一封電子郵件,然後點擊發送。電子郵件顯示在我的收件箱中,但控制器在發送郵件後不會自行解散。當我試圖刪除草稿時,也會發生這種情況,我必須關閉應用程序並重新啓動它。

 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(["[email protected]"]) 
     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(["[email protected]"]) 
     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 

任何幫助將不勝感激。

+1

你想關閉'MFMailComposeViewController'或'FHCLLeftMenuViewController'嗎? – kabiroberai

回答

0

dismissViewControllerAnimated(_:completion:)函數關閉調用該函數的視圖控制器。在這種情況下,由於您在self上調用它,因此它試圖解僱FHCLLeftMenuViewController。可以通過調用MFMailComposeViewController上的dismissViewControllerAnimated(_:completion:)來輕鬆解決此問題。

要做到這一點,只需用下面的代碼替換您mailComposeController(controller:didFinishWithResult:error:)功能(它也出現這樣的蘋果自己的文檔裏):

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) 
} 
0

從崗位尖端沒有工作,但它的是什麼如何設置菜單的代碼(不是因爲建議)。經過一番思考,我想出了一個更好的解決方法。由於該程序同時支持IM消息系統和電子郵件系統,因此我做了以下操作:

1.)將菜單中的支持按鈕鏈接到新視圖控制器&故事板。 1信使或電子郵件支持

出於某種原因,如果不試圖直接從幻燈片菜單辭退,撰寫郵件視圖從視圖控制器駁回:

2)通過加1接觸的選項。不是最優雅的解決方案,但它的工作。