我有系统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
在现有导航堆栈之外模态呈现视图控制器;它不包含在您的 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 快速呈现 ViewController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!