gpt4 book ai didi

ios - 无法在 UIStoryBoard segue 中传递值

转载 作者:行者123 更新时间:2023-11-28 14:52:02 26 4
gpt4 key购买 nike

<分区>

我需要根据某些条件将 bool 值发送到第二个 viewController。但在 Second ViewController 中,bool 变量的值始终为 false。这是第一个 ViewController 代码:

import UIKit

class ViewController: UIViewController {

override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
@IBAction func moveTo(_ sender: Any) {
self.performSegue(withIdentifier: "Move2", sender: self)

}
override func prepare(for segue: UIStoryboardSegue, sender: Any?)
{
if segue.identifier == "Move2"
{
let secondVC = segue.destination as? SecondViewController
secondVC?.second = true

}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}

SecondViewController代码为

import UIKit

class SecondViewController: UIViewController {
var second = Bool()

override func viewDidLoad() {
super.viewDidLoad()
print(second)
// Do any additional setup after loading the view.
}

但是第二个变量的这个值是假的。

我的代码有什么问题。需要帮忙。 TIA..

编辑:在两个 ViewController 中我都有导航 Controller 。那是个问题。 SecondVC 是 SecondViewController 的导航 Controller ,因此我无法将数据传递给该 secondVC。

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