如何在swift中切换视图控制器? [英] How to switch view controllers in swift?

查看:445
本文介绍了如何在swift中切换视图控制器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用代码从一个UIViewController切换到另一个。现在我有,

I'm trying to switch from one UIViewController to another using code. Right now I have,

self.presentViewController(ResultViewController(), animated: true, completion: nil)

所有这一切都是把我带到黑屏而不是ResultViewController。有什么建议么?

All this is doing is taking me to a black screen instead of the ResultViewController. Any suggestions?

推荐答案

使用Storyboard。为第二个视图控制器
创建一个swift文件(SecondViewController.swift),并在相应的函数中输入:

With Storyboard. Create a swift file (SecondViewController.swift) for the second view controller and in the appropriate function type this:

let secondViewController = self.storyboard?.instantiateViewController(withIdentifier: "secondViewController") as! secondViewController

self.navigationController.pushViewController(secondViewController, animated: true)

没有故事板

let secondViewController = ViewController(nibNameOrNil: NibName, bundleOrNil: nil)
self.presentViewController(secondViewController, animated: true, completion: nil)

这篇关于如何在swift中切换视图控制器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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