2016-03-03 25 views
-3

我的項目的目的是爲了有一個登錄/創建賬戶屏幕,用戶點擊一個按鈕,可以發送給他們用自己的用戶名&密碼的電子郵件,以驗證它斯威夫特的Xcode錯誤:「不能分配型‘SendEmailToVerifyPassword’的值鍵入「MFMailComposeViewControllerDelegate?

注:用戶名,密碼和電子郵件在不同的班級我的項目 編輯聲明全局變量:有人說的東西添加到文件的到底是什麼,甚至意味着一個人可以幫

截圖錯誤:?? enter image description here

SendEmailToVerifyPassword類:

import UIKit 
import MessageUI 
class SendEmailToVerifyPassword: MFMailComposeViewController 
{ 
    func ViewDidLoad() 
    { 
     super.viewDidLoad() 
    } 
    func configuredMailComposeViewController() -> MFMailComposeViewController { 
     let mailComposerVC = MFMailComposeViewController() 
     mailComposerVC.mailComposeDelegate = self // Extremely important to set the --mailComposeDelegate-- property, NOT the --delegate-- property 

     mailComposerVC.setToRecipients([email]) 
     mailComposerVC.setSubject("Your password/username verification") 
     mailComposerVC.setMessageBody("Hello.\n Your username is: \(username)\n Your password is \(password)", isHTML: false) 

     return mailComposerVC 
    } 

    func showSendMailErrorAlert() { 
     let sendMailErrorAlert = UIAlertView(title: "Could Not Send Email", message: "Your device could not send e-mail. Please check e-mail configuration and try again.", delegate: self, cancelButtonTitle: "OK") 
     sendMailErrorAlert.show() 
    } 

    func mailComposeController(controller: MFMailComposeViewController, didFinishWithResult result: MFMailComposeResult, error: NSError?) { 

     switch result.rawValue { 

     case MFMailComposeResultCancelled.rawValue: 
      print("Cancelled mail") 
     case MFMailComposeResultSent.rawValue: 
      print("Mail Sent") 
     default: 
      break 
     } 
     self.dismissViewControllerAnimated(true, completion: nil) 
    } 



} 

截圖故事板按鈕視圖 - 控制(點擊這裏是按鈕,我想啓動電子郵件): enter image description here

+2

此添加到文件末尾? '擴展名SendEmailToVerifyPassword:MFMailComposeViewControllerDelegate {}' –

+0

哪一行是「文件的結尾」? – David

+0

文件結尾意味着最後一行 –

回答

0
class SendEmailToVerifyPassword: MFMailComposeViewController, MFMailComposeViewControllerDelegate 
{ 
... 
} 
+0

它的工作,謝謝你。 – David