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
基础教程推荐
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
