简体   繁体   English

推送Segue不起作用

[英]Push Segue Not Working

When I connect a push segue using storyboard, from a view controller to a navigation controller, the app crashes when I try to navigate there and error console shows that: 'Push segues can only be used when the source controller is managed by an instance of UINavigationController.' 当我使用情节提要板将推送脚本从视图控制器连接到导航控制器时,当我尝试在其中导航时应用程序崩溃,并且错误控制台显示:'推送脚本只能在源控制器由的实例管理时使用UINavigationController。”

How do I segue between these two controllers (not using modal). 我如何在这两个控制器之间进行选择(不使用模态)。

And the navigation controller I want to segue to is managed by a tab bar controller. 我想选择的导航控制器由标签栏控制器管理。

Okay there are a few things wrong here. 好的,这里有些错误。 Lets start with the error you're getting. 让我们从您得到的错误开始。

The source controller appears to not have a UINavigationController associated with it. 源控制器似乎没有与之关联的UINavigationController In your storyboard I would click the source view controller and then click the "Editor" menu > "Embed In" > "Navigation Controller". 在您的情节提要中,我将单击源视图控制器,然后单击“编辑器”菜单>“嵌入”>“导航控制器”。 This will make sure that the source controller is now managed by a navigation controller. 这将确保源控制器现在由导航控制器管理。

After you do this though, you will probably still get a crash or an error of somekind. 但是,执行此操作之后,您可能仍然会崩溃或出现某种错误。 You are not allowed to push a UINavigationController onto an existing navigation controller stack. 您不允许将UINavigationController推送到现有的导航控制器堆栈上。

I would take a step back and look at what you are really trying to accomplish here. 我将退后一步,看看您真正在这里要完成什么。 If you simply want the tab bar to go away then you can check off "Hides bottom bar on push" and then when you push the view controller, it will look as if you pushed a whole new navigation controller. 如果您只是希望标签栏消失,则可以取消选中“在按下时隐藏底部栏”,然后在按下视图控制器时,看起来就像您按下了一个新的导航控制器一样。

Otherwise I would question why you are trying to do a push and not a modal. 否则,我会质疑为什么您要进行推送而不是模态。 When presenting a new navigation stack it is common practice to present the stack as a modal. 呈现新的导航堆栈时,通常的做法是将堆栈显示为模式。 Personally it just feels wrong to me to try and present a new stack within an existing stack. 就我个人而言,尝试在现有堆栈中呈现一个新堆栈只是感觉不对。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM