如何选择到新的UIViewController同时还能在Swift 5中初始化新的类?

问题描述 投票:1回答:1

我目前正在研究从另一台VC到另一台VC的Segue,而我想知道如何在这两个View Controller之间传递数据

显然在下面有此实现:

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    if segue.identifier == "someIdentifier" {
        let navigationVC = segue.destination as! UIViewController

        // Pass data to the new object.
        destinationVC.delegate = self
        destinationVC.someStrinng = "someString"
        destinationVC.someBool = true
    }
}

我这种实现方式的问题是,目标VC中的属性具有第一个必须是var(不允许更改)第二个始终是可选的,因为您没有使用这些值初始化类。] >

所以这是我的问题:

使用Storyboard和Segues时,是否有任何初始化目标VC属性的方法,还是只有通过编程才能创建和导航该目标?

非常感谢您的帮助。

我目前正在研究从一个VC到另一个VC的Segue,而我想知道如何在这两个View Controller之间传递数据。显然,下面有此实现:覆盖函数...

ios swift xcode storyboard uikit
1个回答
0
投票

我认为您必须使用自动创建的情节提要来添加脚本。

© www.soinside.com 2019 - 2024. All rights reserved.