gpt4 book ai didi

ios - 在 Swift 中连接多个 Storyboard

转载 作者:行者123 更新时间:2023-11-28 05:29:57 24 4
gpt4 key购买 nike

我正在使用 Swift 构建一个 iOS 应用程序,并且有人建议我为每个功能使用 Storyboard,因为每个功能将有大约 10 个 View 。从主 Storyboard开始,任何人都可以提供有关如何使用 Swift 在 Storyboard之间转换的建议吗?或者,如果我想避免 50+ View 主 Storyboard的困惑,有什么比使用多个 Storyboard更好的方法吗?

这是最终的工作:

let secondVC:UIViewController = UIStoryboard(name: "SecondStoryboard", bundle:nil).instantiateViewControllerWithIdentifier("numberTwo") as UIViewController

@IBAction func changeStoryBoardButtonClicked(sender: AnyObject) {
presentViewController(secondVC, animated: false, completion: nil)
}

最佳答案

当您的应用需要移动到位于不同 Storyboard中的新 Controller 时,您必须实例化新 Storyboard,然后在那里实例化初始 View Controller 。

let sb = UIStoryboard(name: "SomeStoryboardName", bundle: nil)
let vc2 = sb.instantiateInitialViewController() as UIViewController // or whatever the class is of that initial vc

关于ios - 在 Swift 中连接多个 Storyboard,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29177085/

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