Swift Programming Language我开始查看UIViewController.UIStoryboard
Swift Programming Language
UIViewController
UIStoryboard
在Objective-C我简单地写下:
Objective-C
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"StoryboardName" bundle:nil]; UIViewController *viewController = [storyboard instantiateViewControllerWithIdentifier:@"ViewControllerID"]; [self presentViewController:viewController animated:YES completion:nil];
谁能帮助我如何在 Swift 上实现这一目标?
此答案是针对 Swift 5.4 和 iOS 14.5 SDK 的最后修订的。
这完全是新语法和稍微修改的 API 的问题。UIKit 的底层功能没有改变。绝大多数 iOS SDK 框架都是如此。
let storyboard = UIStoryboard(name: "myStoryboardName", bundle: nil) let vc = storyboard.instantiateViewController(withIdentifier: "myVCID") self.present(vc, animated: true)
确保设置myVCID在情节提要内部的“情节提要 ID”下。
myVCID