问题描述
我开始查看 Swift Programming Language
,但不知何故,我无法从特定 UIStoryboard<正确键入
UIViewController
的初始化/代码>.
I started taking a look on the Swift Programming Language
, and somehow I am not able to correctly type the initialization of a UIViewController
from a specific UIStoryboard
.
在 Objective-C
我简单地写:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"StoryboardName" bundle:nil];
UIViewController *viewController = [storyboard instantiateViewControllerWithIdentifier:@"ViewControllerID"];
[self presentViewController:viewController animated:YES completion:nil];
谁能帮助我如何在 Swift 上实现这一目标?
Can anyone help me on how to achieve this on Swift?
推荐答案
此答案最后针对 Swift 5.4 和 iOS 14.5 SDK 进行了修订.
这完全是新语法和稍微修改的 API 的问题.UIKit 的底层功能没有改变.绝大多数 iOS SDK 框架都是如此.
It's all a matter of new syntax and slightly revised APIs. The underlying functionality of UIKit hasn't changed. This is true for a vast majority of iOS SDK frameworks.
let storyboard = UIStoryboard(name: "myStoryboardName", bundle: nil)
let vc = storyboard.instantiateViewController(withIdentifier: "myVCID")
self.present(vc, animated: true)
确保在情节提要中的情节提要 ID"下设置 myVCID
.
Make sure to set myVCID
inside the storyboard, under "Storyboard ID."
这篇关于在 Swift 中实例化并展示一个 viewController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!