segue并发送电子邮件swift

时间:2015-08-18 18:03:32

标签: ios swift email segue

我是IOS快速开发的新手,我想知道:当发送电子邮件时,是否可以在发送电子邮件之后或从发送电子邮件时发送电子邮件的消息mailComposeViewController并将其转换为新的视图控制器。谢谢你的帮助。

@IBAction func sendEmail(sender: UIButton) {
    let mailComposeViewController = configuredMailComposeViewController()
    if (textField1.text.isEmpty || textField2.text.isEmpty || textField3.text.isEmpty) 
      {
        println("Error")
      } 
    else 
     {
        if MFMailComposeViewController.canSendMail() 
       {
   self.presentViewController(mailComposeViewController, animated: true, completion: nil)     
        } 
       else 
        {
            self.showSendMailErrorAlert()
        }

    }
func configuredMailComposeViewController() -> MFMailComposeViewController {

    let mailComposerVC = MFMailComposeViewController()
    mailComposerVC.mailComposeDelegate = self

    mailComposerVC.setToRecipients(["email.test@gmail.com"])
    mailComposerVC.setSubject("Title")
    //the message body is filed with 3 textFields, already declared
    //need to send then to another view after send email
    mailComposerVC.setMessageBody(textField1.text+textField2.text+textField3.text,
        isHTML: true)

    return mailComposerVC
}

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {

    if (segue.identifier == "send") {
        var view: UIViewController = segue.destinationViewController as! UIViewController
        //the same textFields in email here...
        //blank
    }
}

编辑:第二个视图有一个数组,我需要用field1,2和3填充这个数组,例如:

if (segue.identifier == "send") {
        var view: UIViewController = segue.destinationViewController as! UIViewController
        view.array = [textField1.text, textField2.text, textField3.text]
    }
}

这是我想要的第二个观点:

class Agenda: UITableViewController {

var array = []

var end = ""
var area = ""
var data = ""

override func viewDidLoad() {
    super.viewDidLoad()

    end = self.array[0] as! String
    area = self.array[1] as! String
    data = self.array[2] as! String
}

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

// MARK: - Table view data source

override func numberOfSectionsInTableView(tableView: UITableView) -> Int {

    return 1
}

override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

    return self.array.count
}

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! AgendaCell

    cell.endereco.text = end
    cell.area.text = area
    cell.data.text = data

    return cell
    }
}

细胞有3个标签,每个标签需要按顺序归档,那是我如何制作的?

1 个答案:

答案 0 :(得分:1)

您应该将三个文本字段文本连接成一个fullMessage,然后准备一些字符串或数据结构来接收它

var fullMessage :String {
  return textfield.text + textfield1.text + textfield2.text
}

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    if segue.identifier == "send "{
     var destination = segue.destinationViewController as! UIViewController
      destination.recievemessage = fullMessage

    }
}