在 Swift 中实例化并展示一个 viewController

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

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Why local notification is not firing for UNCalendarNotificationTrigger(为什么没有为UNCalendarNotificationTrigger触发本地通知)
iOS VoiceOver functionality changes with Bundle Identifier(IOS画外音功能随捆绑包标识符而变化)
tabbar middle tab out of tabbar corner(选项卡栏中间的选项卡角外)
Pushing UIViewController above UITabBar(将UIView控制器推送到UITabBar上方)
Dropbox Files.download does not start when number of files in folder is gt; 1000(当文件夹中的文件数为1000时,Dropbox Files.Download不会启动)
How can I sync two flatList scroll position in react native(如何在本机Reaction中同步两个平面列表滚动位置)