我想要做的是我在MainViewController中创建了TextField,用户输入了他/她的id,所以我编码:
@IBOutlet weak var IdNum: UITextField!
和
var Id = self.IdNum.text
在viewDidLoad中。
现在我想获取该值并在属于另一个ViewController (FirstViewController)
@IBAction func Messages(_ sender: UIButton) {
if MFMessageComposeViewController.canSendText() == true {
let recipients:[String] = ["1500"]
let messageController = MFMessageComposeViewController()
messageController.messageComposeDelegate = self // implement delegate if you want
messageController.recipients = recipients
messageController.body = "*155*"+"Id"+"#"
self.present(messageController, animated: true, completion: nil)
}
}
func messageComposeViewController(_ controller: MFMessageComposeViewController, didFinishWith result: MessageComposeResult) {
self.dismiss(animated: true)
}
messageController.body = "*155*"+"Id"+"#"
中的ID是TextFiled内容,任何帮助都会有用。
答案 0 :(得分:0)
您可以将值发送到下一个屏幕,如下所示:
let VCObejct = self.storyboard?.instantiateViewController(withIdentifier: "NextViewController") as? NextViewController
VCObejct?.objToSend = obj//value to send
navigationController?.pushViewController(VCObejct!, animated: true)
或
self.present(VCObejct, animated: true, completion: nil)
您需要在NextViewController中定义objToSend,如下所示:
@IBOutlet weak var vwPost: UIView?
您也可以通过在Segue中设置它并从Mar-k解释的方式使用它来从故事板中完成。