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
基础教程推荐
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
