自定义 UIModalViewController 大小并拥有导航栏
我创建了自己的 ProfileUIViewController
类,它是一个 UINavigationControllerDelegate
。我以两种方式显示此视图:
从
A-UIViewController.m
中的 IBAction,作为UIModalViewController
。A-UIViewController
加载时有一个UINavigationBar
,但是当我显示模式时,它不再具有导航栏。通过单击
B-UIViewController.m
中的表格单元格行,将其推入堆栈。B-UIViewController
在加载时有一个UINavigationBar
,并且ProfileViewController
根据需要保留导航栏:)
我想要做的是保留在情况 1 中,当视图作为模态加载时,UINavigationBar 会填充到 UINavigationBar 内部,而不是覆盖整个视图。 (即,我希望模式出现在导航栏下方的 A-UIViewConroller
中 - 使其尺寸更小)
有人可以帮助我吗?我是否需要创建自己的自定义 ModalViewController
类 - 这不是 ProfileUIViewController
吗?它是否需要一些我没有提供的实例方法?任何方向都会很棒:)
I've created my own ProfileUIViewController
class that is a UINavigationControllerDelegate
. I display this view in two ways:
From an IBAction within
A-UIViewController.m
, as aUIModalViewController
.A-UIViewController
has aUINavigationBar
when it's loaded, but when I display the modal, it no longer has the navigation bar.From clicking a table cell row within
B-UIViewController.m
, by pushing it onto the stack.B-UIViewController
has aUINavigationBar
when it's loaded, and theProfileViewController
keeps the navBar as desired :)
What I am looking to do is keep the UINavigationBar when the view is loaded as a modal in case 1, filling in INSIDE the UINavigationBar instead of laying over the entire view. (IE, I would like the modal to appear within A-UIViewConroller
underneath the navBar - making it a smaller size)
Can someone help me with this? Do I need to make my own custom ModalViewController
class - wouldn't this be ProfileUIViewController
? Does it need some instance methods that I'm not giving it? Any direction would be great:)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
导航栏由导航控制器管理,而不是由视图控制器管理。当您将视图控制器推入导航控制器时,导航控制器使用 navigationItem 中的信息来确定要在导航栏中放置的内容。但是,当您以模态方式显示视图控制器时,它不在任何导航控制器内,因此没有栏。
针对模态情况的一种简单解决方案是创建一个新的 UINavigationController,并将视图控制器作为其根视图控制器,并以模态方式显示该视图控制器,而不是直接显示视图控制器。
The navigation bar is managed by the navigation controller, not by your view controller. When you push your view controller into the navigation controller, the navigation controller uses the information in the navigationItem to determine what to put in the navigation bar. But when you display your view controller modally, it's not inside any navigation controller so there is no bar.
One simple solution for the modal case is to create a new UINavigationController with your view controller as its root view controller, and display that modally instead of displaying your view controller directly.