gpt4 book ai didi

swift - 我是否正确使用 Storyboard?

转载 作者:行者123 更新时间:2023-11-28 14:12:36 24 4
gpt4 key购买 nike

我使用的 Storyboard对吗?

我有几个带有 View Controller 的 Storyboard。


当我需要在它们之间导航时,我会执行以下操作:

每次使用它们时,我都会创建 Storyboard的新实例 let storyboard = ...。这是一个糟糕的方法吗?或者我应该在 view did load 中声明它吗?

func detailsRequestedForMessage(message: message) {

let storyboard = UIStoryboard(name: "Additional", bundle: nil)
let viewController = storyboard.instantiateViewController(withIdentifier: "MessageDetailsViewController") as! MessageDetailsViewController

viewController.messageId = message.id
self.navigationController?.pushViewController(viewController, animated: true)
}

func viewAllMessage() {

let storyboard = UIStoryboard(name: "Additional", bundle: nil)
let viewController = storyboard.instantiateViewController(withIdentifier: "AllMessageViewController") as! AllMessageViewController

self.navigationController?.pushViewController(viewController, animated: true)
}

func viewOptions() {

let storyboard = UIStoryboard(name: "Options", bundle: nil)
let viewController = storyboard.instantiateViewController(withIdentifier: "OptionsViewController") as! OptionsViewController

self.present(viewController, animated: true)
}

最佳答案

存储 Storyboard引用不需要任何费用,但需要时间从名称解析 Storyboard引用。所以我会说你应该把这样的行放在

self.storyboardAdditional = UIStoryboard(name: "Additional", bundle: nil)

viewDidLoad中,将引用存储在属性中,然后通过属性引用 Storyboard。

关于swift - 我是否正确使用 Storyboard?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52414675/

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