Well I have a problem with my app. Just to say I m a beginner :) I have TableViewControler and I am using func with dequeueReusableCell to return a cell I that is ok. But the problem is how to implement this cell(s) with their values into a body mail using MFMailComposeViewController.setMessageBody? I m trying to pass an order which is in cells just like it is - in a table. That table a need to be visible in mail body. This parameter only takes String and cell is not visible (in scope here). Maybe should I transform cell into a html? And how should I do that?
//This values/cells I need to implement into a mail body//
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: "OrderProductsCell", for: indexPath) as! OrderViewCell
let rowData = orderedProducts[indexPath.row]
cell.lblNameOfOrderProduct.text = rowData.selectedProducts.name + " " + rowData.selectedProducts.packaging + " " + rowData.selectedProducts.volume + " " + String(rowData.stepperNumber) + " x(kom)"
cell.lblFromDistributor.text = "Od"
cell.lblToStore.text = "Za"
cell.tfOrderFromDistibutor.text = String(rowData.distibutor)
cell.tfOrderToStore.text = String(rowData.store)
cell.tfOrderFromDistibutor.isUserInteractionEnabled = false
cell.tfOrderToStore.isUserInteractionEnabled = false
return cell
}
//This is MFMailComposeViewControlles - in the same Controller like Table View
func showMailComposer() {
guard MFMailComposeViewController.canSendMail() else {
defAlert(name: "You Can't sent mail", message: "")
return
}
let composer = MFMailComposeViewController()
composer.mailComposeDelegate = self
composer.setToRecipients(["[email protected]"])
composer.setSubject("Porudzbina")
composer.setMessageBody ("Here i need to implement cell", isHTML: false)
present(composer,animated: true)
}
I am not sure I understand your end goal completely, but let me share what I think you mean.
I believe you want all the texts from your table view to show inside the MailView as text.
And I understand all your products data is inside
orderedProducts- correct me if I am wrong ?So inside your
showMailComposerfunction, you can maybe try this - I have added comments to new code I have added to your function:Run this result and check if it is close to what you want, it will give an output like this:
Update
If you want to format the text a bit better in the MFMailComposeViewController you can use HTML and you need to know some basics of HTML like table as you suggested or other techniques like div.
Here is example of your function using table to organize the output:
The generated HTML from above code is actually like this
Final result gives you data organized in a table.
This is just basic HTML and you can do more styling and change how the output looks as you wish.