这个问题是在另一个帖子中提出的,我无法让他们解释他们的意思。我认为 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 storyboard
是 UIViewController
的属性是正确的。您感到困惑的原因是您的心智模型假设因为 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/