以编程方式从 Iphone UIViewController 到 UINavigation 控制器
我已经被困在这个问题上几天了,这让我很痛苦......在我的 viewDidLoad 事件中,我试图以编程方式将全屏 UINavigationController 添加到我的视图控制器的子视图中。到目前为止,我只成功做了两件事......
1)只显示灰屏
或
2)我得到了一些类似于添加到视图控制器中的导航控制器的东西,而不是来自 XIB 的导航控制器,它只是一个通用的控制器......即使我从 XIB 加载。奇怪的是,它总是向下移动 25 像素并稍微被切断。
我已经阅读了谷歌上的每一个链接,但我似乎无法弄清楚这一点。我刚刚创建了一个新的视图控制器...向其中添加了一个 UINavigationController...尝试加载该视图控制器,但它弄乱了。
非常感谢任何帮助!
I have been stuck on this for a few days now and it is killing me... In my viewDidLoad event, I am trying to programmatically add a full screen UINavigationController to a subview of my view controller. So far, I have only succeeded in doing two things...
1) Only a grey screen shows up
OR
2) I get something that resembles a navigation controller added to the view controller, instead of being my navigation controller from a XIB it is just a generic one... even though I loaded from the XIB. Oddly enough it is always shifted 25 pixels downward and slightly cut off.
I have read every single link on google and I can't seem to figure this out. I just created a new viewcontroller... added a UINavigationController to it... try to load that view controller and it messes up.
Any help is greatly appreciated!!!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不要让 UINavigationController 成为其他视图控制器的子级,而是让 UINavigationController 本身成为根控制器。导航控制器是特殊的“容器”视图控制器之一,它通常希望拥有整个屏幕并位于控制器层次结构的根部(某些情况除外)。
尝试这样的操作:
这将掩盖导航控制器的任何现有视图(当您
-removeFromSuperview
导航控制器的视图时,那些现有的东西仍然存在)。核心选项是使用导航控制器设置 UIWindow 的 rootViewController 属性,但从您的评论中听起来,这可能不是您想要在此处执行的操作。可能是一种更干净的方法:如果它实现了您想要的,我相信您也可以使用您的导航控制器并从当前视图控制器中以模态方式呈现它(请参阅 uiviewcontroller 的文档)。适当设置过渡,当您位于导航堆栈中时,导航控制器将可见。
Instead of having the UINavigationController be a child of some other view controller, make the UINavigationController the root controller itself. The navigation controller is one of the special "container" view controllers, and it generally wants to own the whole screen and be at the root of the controller hierarchy (except in certain circumstances).
Try something like this:
Which will obscure any existing views with the nav controller (those existing things will still be there when you
-removeFromSuperview
the nav controller's view). The nuclear option is to set your UIWindow'srootViewController
property with the nav controller, but it sounds from your comment that this may not be what you want to do here.Possibly a cleaner approach: If it accomplishes what you want, I believe you could also take your nav controller and present it modally (see docs for uiviewcontroller) from whatever the current view controller is. Set the transition appropriately, and while you're in the nav stack, the nav controller will be visible.