MFMailComposeViewController setToRecipients从设置文本字段追加字符串麻烦 [英] MFMailComposeViewController setToRecipients append String from settings textField trouble
问题描述
希望这是一个简单的问题?但是我似乎无法解决这个问题.
Hopefully this is a simple issue? But I just cant seem to get my head around it.
我的settingsViewController中有一个名为emailText的文本字段,我想在其中设置默认电子邮件收件人.
I have a text field in my settingsViewController called emailText where I want to set the default email recipient.
@IBOutlet weak var emailText: UITextField!
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
let shoppingListViewController = segue.destinationViewController as! ShoppingListViewController
shoppingListViewController.emailString = ([emailText.text]!)
}
func textFieldShouldReturn(emailText: UITextField) -> Bool {
emailText.resignFirstResponder()
print ((emailText.text)!) //This prints the correct email address in the console.
return true;
}
我的shoppingListViewController通过以下方式接收此字符串:
My shoppingListViewController recieves this string by the following:
var emailString = ""
mailComposerVC.setToRecipients ([emailString])
我的问题是,当我按我的按钮打开电子邮件时,我得到了2016-05-26 14:25:14.617我的APP名称[1397:520893]在控制台中不是有效的电子邮件地址? 在打开的电子邮件中还有一个空白的收件人:"字段.
My problem is that when I press my button to open the email I get 2016-05-26 14:25:14.617 MY APP Name [1397:520893] is not a valid email address in the console? And a blank To: field in the opened email.
我要去哪里错了?
推荐答案
好,所以我仍然想解决问题.我会再次提出我的问题,希望有人会注意到我的说法不太正确.
Ok, so I'm still stuck for a fix. Ill lay out my issue again, in hopes that somebody will notice something not quite right with my segue.
我有一个UITabBarController-它具有3个选项卡(1)产品列表(2)购物列表(3)设置.因此,这三个视图都具有UINavigationViewControllers. 我的设置"页面中有一个文本字段",用于设置MFMailComposeViewController的默认收件人电子邮件地址(mailComposerVC.setToRecipients),该按钮是通过从shopListViewController中按下按钮启动的. (邮件正常工作,我只是不明白我的意思:填充了地址字符串) 我可以从settingsViewController进行打印以控制台文本字段(emailText.text). 我的命令并没有一直传递到shoppingListViewController,在这里它需要作为字符串.
I have a UITabBarController - It has 3 Tabs (1)Product List (2)Shopping List (3)Settings. So all three views also have UINavigationViewControllers. I have a Text Field in my Settings page to set the default recipient email address for MFMailComposeViewController (mailComposerVC.setToRecipients) which is launched by button press from shoppingListViewController. (Mail is working, I just don't get my to: address string populated) I can print to console the text field (emailText.text) just fine from settingsViewController. My segue does not carry all the way through to shoppingListViewController where it is required as a string.
SettingsVC(emailText)-> TabBarController-> NavController(2nd)-> ShoppingListVC(emailString ="emailText.text")-> mailComposerVC.setToRecipients([emailString])
SettingsVC (emailText) --> TabBarController --> NavController (2nd) --> ShoppingListVC (emailString = "emailText.text") --> mailComposerVC.setToRecipients([emailString])
我的搜寻现在看起来像下面,但是仍然迷路了.
My segue now looks like the following, but is still getting lost on the way.
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
let tabBarController = segue.destinationViewController as! UITabBarController
let nav = tabBarController.viewControllers![2] as! UINavigationController
let shoppingListViewController = nav.topViewController as? ShoppingListViewController
shoppingListViewController!.emailString = emailText.text
}
这篇关于MFMailComposeViewController setToRecipients从设置文本字段追加字符串麻烦的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!