博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Swift presenting ViewController with NavigationViewController
阅读量:4704 次
发布时间:2019-06-10

本文共 1700 字,大约阅读时间需要 5 分钟。

Q:

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 ViewControllerself.presentViewController(VC1, animated:true, completion: nil)

 

A:

 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:

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

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

 

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// Create a navigation controller with VC1 at the root of the navigation stack.let navController = UINavigationController(rootViewController: VC1)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.

 

转载于:https://www.cnblogs.com/moiez/p/9590734.html

你可能感兴趣的文章
azkaban用户管理及权限配置
查看>>
GCD学习笔记
查看>>
PHP......会话控制SESSION与COOKIE
查看>>
[转]AchartEngineActivity引擎绘制柱状图、曲线图
查看>>
[转]javascript实现限制上传文件的大小
查看>>
我的Java设计模式-策略模式
查看>>
C# 报表接口样例,简单实用
查看>>
C++常见内存错误及解决方案
查看>>
控制台应用程序窗口无法输入汉字解决办法
查看>>
Java中实现String.padLeft和String.padRight
查看>>
winCVS 使用的一个小要点
查看>>
一个关于session的问题
查看>>
加快开发时间的8个CSS的预处理程序
查看>>
dom元素高度、屏幕高度 获取
查看>>
asp.net 设置session失效时间
查看>>
杭电多校第四场 E Matrix from Arrays
查看>>
ReactiveCocoa操作方法-线程\时间
查看>>
oracle 分析函数
查看>>
CHD-5.3.6集群上sqoop安装
查看>>
解决无/var/log/messages 问题
查看>>