使用NavigationViewController swift呈现ViewController [英] presenting ViewController with NavigationViewController swift

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

问题描述

我有系统NavigationViewController - > MyViewController,我以编程方式想要在第三个视图控制器中呈现MyViewController。问题是我在呈现它之后在MyViewController中没有导航栏。你可以帮我吗?

I have system "NavigationViewController -> MyViewController", and I programmatically want to present MyViewController inside a third view controller. The problem is that I don't have navigation bar in MyViewController after presenting it. Can you help me?

var VC1 = self.storyboard.instantiateViewControllerWithIdentifier("MyViewController") as ViewController
self.presentViewController(VC1, animated:true, completion: nil)


推荐答案

调用 presentViewController 在现有导航堆栈之外呈现视图控制器 modally ;它不包含在您的UINavigationController或任何其他内容中。如果您希望新视图控制器具有导航栏,则有两个主要选项:

Calling presentViewController presents the view controller modally, outside the existing navigation stack; it is not contained by your UINavigationController or any other. If you want your new view controller to have a navigation bar, you have two main options:

选项1.将新视图控制器推送到现有导航堆栈,而不是以模态方式呈现:

Option 1. Push the new view controller onto your existing navigation stack, rather than presenting it modally:

let VC1 = self.storyboard!.instantiateViewControllerWithIdentifier("MyViewController") as! ViewController
self.navigationController!.pushViewController(VC1, animated: true)

选项2。将新的视图控制器嵌入到新的导航控制器中并以模态方式显示新的导航控制器:

Option 2. Embed your new view controller into a new navigation controller and present the new navigation controller modally:

let VC1 = self.storyboard!.instantiateViewControllerWithIdentifier("MyViewController") as! ViewController
let navController = UINavigationController(rootViewController: VC1) // Creating a navigation controller with VC1 at the root of the navigation stack.
self.present(navController, animated:true, completion: nil)

记住此选项不会自动包含后退按钮。你必须自己构建一个紧密的机制。

Bear in mind that this option won't automatically include a "back" button. You'll have to build in a close mechanism yourself.

哪个最适合你的是一个人机界面设计问题,但通常很清楚什么是最有意义的。

Which one is best for you is a human interface design question, but it's normally clear what makes the most sense.

这篇关于使用NavigationViewController swift呈现ViewController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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