gpt4 book ai didi

ios - 如何在不使用 segue 的情况下快速导航并将数据传递到另一个 View Controller

转载 作者:行者123 更新时间:2023-11-29 12:06:12 25 4
gpt4 key购买 nike

嗨,我是 swift 的新手。我有疑问。我有一个 View Controller ,其中有一个文本框和按钮,同样我有第二个 View Controller ,其中有一个文本框和按钮。每当我按下第一个 View Controller 的按钮时,我都想这样做第二个 View Controller 出现,第一个 View Controller 的文本框的数据将传递到第二个 View Controller 的文本框,但不使用 segue。请帮助我。

最佳答案

在 FirstViewController.swift 中

@IBAction weak var textFiled: UITextField!

@IBAction func sendDatatoNextVC(sender: UIButton) {
let mainStoryboard = UIStoryboard(name: "Storyboard", bundle: NSBundle.mainBundle())
let vc : SecondViewController = mainStoryboard.instantiateViewControllerWithIdentifier("SecondViewControllerSBID”) as SecondViewController
vc. recevedString = textFiled.text
self.presentViewController(vc, animated: true, completion: nil)
}

在 SecondViewController.swift 中

var recevedString: String =  “”

@IBAction weak var textFiled2: UITextField!

override func viewDidLoad() {
super.viewDidLoad()
textFiled2.text = recevedString

}

关于ios - 如何在不使用 segue 的情况下快速导航并将数据传递到另一个 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34916869/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com