我的代码从文本字段中获取文本并转到单独的视图控制器。问题是它只能存储 1 个 segue 条目。每次按下按钮时,新的都会替换旧的。如何在 vc2 上将每个新条目存储到 segue。
风险投资
import UIKit
class ViewController: UIViewController {
@IBOutlet var txt: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
}
@IBAction func pressButton(_ sender: Any) {
if txt.text != "" {
performSegue(withIdentifier: "segue", sender: self)
}
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
let secondController = segue.destination as! twoViewController
secondController.myString = txt.text!
}
}
两个VC
import UIKit
class twoViewController: UIViewController {
@IBOutlet var labelSmtih: UILabel!
var myString = String()
override func viewDidLoad() {
super.viewDidLoad()
labelSmtih.text = myString
}
}