在Swift中实例化和呈现viewController [英] Instantiate and Present a viewController in Swift

查看:130
本文介绍了在Swift中实例化和呈现viewController的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始在 Xcode 6上看一下新的 Swift ,我尝试了一些演示项目和教程。现在我被困在:

I started taking a look of the new Swift on Xcode 6, and I tried some demo projects and tutorials. Now I am stuck at:

实例化然后从特定故事板中呈现 viewController

Instantiating and then presenting a viewController from a specific storyboard

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"myStoryboardName" bundle:nil];
UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"myVCID"];
[self presentViewController:vc animated:YES completion:nil];

如何在Swift上实现这一目标?

How to achieve this on Swift?

推荐答案

这一切都是新语法的问题,功能没有改变:

It all is a matter of the new syntax, functionality hasn't changed:

// Swift 3.0

let storyboard = UIStoryboard(name: "MyStoryboardName", bundle: nil)
let controller = storyboard.instantiateViewController(withIdentifier: "someViewController")
self.present(controller, animated: true, completion: nil)

如果您遇到问题 init(编码器:),请参阅 EridB的回答

If you're having problems with init(coder:), please refer to EridB's answer.

这篇关于在Swift中实例化和呈现viewController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆