我开始查看 Swift Programming Language
,但不知何故,我无法从特定 UIStoryboardUIViewController
的初始化。
在 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)
确保在 Storyboard 中的“ Storyboard ID”下设置 myVCID
。
https://stackoverflow.com/questions/24035984/