如何在导航控制器 SWIFT 中显示视图控制器 [英] How to present a view controller inside a navigation controller SWIFT

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

问题描述

我有 VC1,它是一个基本的视图控制器,然后我想展示位于导航控制器内的 VC2.每当我展示它时,它都不会显示导航控制器.我希望这一切以务实的方式完成.我一直用来展示 VC2 的代码是:

I have VC1 which is a basic view controller, I then want to present VC2 which is inside a navigation controller. Whenever I present it, it doesn't display the navigation controller. I want this all done pragmatically. The code I have been using to present VC2 is:

func matchesPressed(sender: UIButton!) {
    let matchesTVC: Matches = self.storyboard?.instantiateViewControllerWithIdentifier("Matches") as! Matches
    self.presentViewController(matchesTVC, animated: true, completion: nil)

}

如何展示它内部的导航控制器?

How do I present the navigation controller it is inside as well?

推荐答案

导航控制器是否在故事板中?如果是这样,给它一个故事板 ID 并用导航控制器替换你的 matchesTVC 内容.

Is the navigation controller in the storyboard? If so, give it a storyboard ID and replace your matchesTVC stuff with the navigation controller.

如果matches是故事板中的一个独立的视图控制器,你可以用这样的代码来实现:

If matches is a standalone view controller in the storyboard, you can do it in code like this:

let matchesTVC: Matches = self.storyboard?.instantiateViewControllerWithIdentifier("Matches") as! Matches 
let navContr = UINavigationController(rootViewController:matchesTVC)
self.presentViewController(navContr, animated: true, completion: nil)

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

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