Instantiate and Present a viewController in Swift(在 Swift 中实例化并展示一个 viewController)
问题描述
我开始查看 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 Swift 中实例化并展示一个 viewController


- Android viewpager检测滑动超出范围 2022-01-01
- 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01
- 用 Swift 实现 UITextFieldDelegate 2022-01-01
- 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01
- MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01
- Android - 拆分 Drawable 2022-01-01
- 想使用ViewPager,无法识别android.support.*? 2022-01-01
- 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01
- Android - 我如何找出用户有多少未读电子邮件? 2022-01-01
- android 4中的android RadioButton问题 2022-01-01