presenting ViewController with NavigationViewController swift(用 NavigationViewController 快速呈现 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
在现有导航堆栈之外模态呈现视图控制器;它不包含在您的 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:用 NavigationViewController 快速呈现 ViewController


基础教程推荐
- 如何使 UINavigationBar 背景透明? 2022-01-01
- Android ViewPager:在 ViewPager 中更新屏幕外但缓存的片段 2022-01-01
- 使用 Ryzen 处理器同时运行 WSL2 和 Android Studio 2022-01-01
- 固定小数的Android Money Input 2022-01-01
- 在 iOS 上默认是 char 签名还是 unsigned? 2022-01-01
- :hover 状态不会在 iOS 上结束 2022-01-01
- LocationClient 与 LocationManager 2022-01-01
- 如何使用 YouTube API V3? 2022-01-01
- Android文本颜色不会改变颜色 2022-01-01
- “让"到底是怎么回事?关键字在 Swift 中的作用? 2022-01-01