Swift presentViewController [英] Swift presentViewController

查看:955
本文介绍了Swift presentViewController的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我以编程方式在iOS Swift项目中拥有多个View Controller。我没有故事板,如果可能的话想避免使用它们。有没有办法切换到另一个 viewcontroller.swift 文件(我们称之为 view2.swift )并拥有它成为按钮调用的函数的一部分?
我尝试过以下内容:

I programatically have multiple View Controllers in an iOS Swift Project. I do not have the storyboards and would like to avoid them if possible. Is there a way to switch to another viewcontroller.swift file (We will call it view2.swift) and have it be part of a function that a button calls?
I have tried the following:

let storyboard: UIStoryboard = UIStoryboard(name: "myTabBarName", bundle: nil)
let vc: UIViewController = storyboard.instantiateViewControllerWithIdentifier("myVCID") as UIViewController
self.presentViewController(vc, animated: true, completion: nil)

以上适用于故事板,但我想要另一个 view2.swift 被召唤。可以这样做吗?

The above works with storyboards, but I want another view2.swift to be called. Can this be done?

推荐答案

试试这个:

let vc = ViewController() //change this to your class name
self.presentViewController(vc, animated: true, completion: nil)

使用Swift3:

self.present(vc, animated: true, completion: nil)

这篇关于Swift presentViewController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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