ios - Storyboard属性是 UIViewController 的属性吗?

标签 ios uiviewcontroller storyboard

这个问题是在另一个帖子中提出的,我无法让他们解释他们的意思。我认为 Storyboard是 UIViewController 的一个属性,因为 Apple 的引用文档在“与 Storyboard和 Segues 交互”的区域中说了 var Storyboard。 Apple UIViewController reference doc其中一条评论是“ Storyboard 不是 UIViewController 的属性或特性”,我希望他们能对此进行详细说明。谁能帮忙,因为现在我对自己是否正确阅读或使用引用文档感到困惑。

最初的问题在这里:original question

最佳答案

在文档中,定义指出:

var storyboard: UIStoryboard?

The storyboard from which the view controller originated.

您认为 var storyboardUIViewController 的属性是正确的。您感到困惑的原因是您的心智模型假设因为 UIViewController 引用了 storyboard,它必须拥有它。 storyboard 只是对加载您的UIViewController 的 Storyboard的引用。它应该更多地被视为一种自下而上的关系,而不是自上而下的关系。

在实践中,作为一个 UIViewController,一个常见的用例是要求您的 storyboard 实例化其他 UIViewController,然后我们可以呈现:

let viewControllerToPresent = storyboard?.instantiateViewController(withIdentifier: "presentedController")
present(viewControllerToPresent, animated: true, completion: nil)

关于ios - Storyboard属性是 UIViewController 的属性吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50090237/

相关文章:

ios - Swift 4 从JSON中获取相关数据

我页面上的 Javascript 在 iOS 中不工作

ios - 为什么在我的每个新 xcode 项目中都会显示两个 Storyboard?

ios - 处理屏幕尺寸的正确方法

ios - 在 iOS7 中安装二进制文件时的奇怪行为

ios - 动态改变 mkpolyline 的线宽

ios - 在应用程序内更改语言后更新所有 UIViewController

swift - 自定义 UIViewControllerAnimatedTransitioning 完成后显示黑屏

ios - 居中 UIView

ios - 找不到名为的 Storyboard