ios NSGenericException', reason: 'push segues 只能在源控制器由 UINavigationController 的实例管理时使用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13546122/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
NSGenericException', reason: 'Push segues can only be used when the source controller is managed by an instance of UINavigationController
提问by DouglasBoone
so I'm making an app with 5 view controllers, the first is embedded in a UINavigationController and the segue between the first 4 view controllers works fine. However introducing a 5th View Controller has broken this, and I'm getting the error
所以我正在制作一个带有 5 个视图控制器的应用程序,第一个嵌入在 UINavigationController 中,并且前 4 个视图控制器之间的 segue 工作正常。然而,引入第 5 个视图控制器已经打破了这一点,我收到了错误
Terminating app due to uncaught exception 'NSGenericException', reason: 'Push segues can only be used when the source controller is managed by an instance of UINavigationController.'
I havent done anything differently with this 5th view controller, its just a standard ViewController with an image view and a label, and all of my segues are called by ctrl dragging buttons in the storyboard. Does anybody have any idea whats causing this?
我没有对这个第 5 个视图控制器做任何不同的事情,它只是一个带有图像视图和标签的标准 ViewController,我所有的 segue 都是通过 ctrl 拖动故事板中的按钮来调用的。有谁知道这是什么原因造成的?
Thanks
谢谢
回答by Kirit Vaghela
add Navigation Controller to your initial view
将导航控制器添加到您的初始视图
- Select the initial view
- Go To Editor--> Embed In--> Navigation Controller.
- 选择初始视图
- 转到编辑器-->嵌入-->导航控制器。
回答by Vinay
Set UINavigationcontroller as Initial View controller (Initial Scene) in StoryBoard.
在 StoryBoard 中将 UINavigationcontroller 设置为初始视图控制器(初始场景)。
回答by Gaston
In my case at the time the original VC performed the segue, the Navigation Controller was transitioning and already changed he visible VC.
在我的情况下,当原始 VC 执行 segue 时,导航控制器正在转换并且已经改变了他可见的 VC。
I solved it by doing:
我通过执行以下操作解决了它:
if (self.navigationController.visibleViewController == self) {
[self performSegueWithIdentifier:@"thankyou" sender:self];
}
no more crash. :)
没有更多的崩溃。:)
回答by Yosep Kim
This is most likely because your push segue from the button or whatever is pointing to a view controller not the navigation view controller your view controller inherits. So, you have to point the segue to the navigation controller.
这很可能是因为您从按钮或任何指向视图控制器而不是您的视图控制器继承的导航视图控制器的推式转场。因此,您必须将 segue 指向导航控制器。
Hope this helps.
希望这可以帮助。
回答by Nicholas Chew
You just need to embed a Navigation Controller into your Source View Controller ( The one initial view, not the view you are pushing for ) . This can be done by selecting the Source View Controller and Go To Editor--> Embed In --> Navigation Controller.
您只需要将一个导航控制器嵌入到您的源视图控制器中(一个初始视图,而不是您正在推动的视图)。这可以通过选择 Source View Controller 和 Go To Editor--> Embed In --> Navigation Controller 来完成。
If you think that the Navigation Bar that the Navigation Controller has done . Simply select the Navigation Controller , In the "Show the Attributes Inspector" disable the Shows Navigation Bar.
如果你认为 Navigation Bar 就是 Navigation Controller 所做的。只需选择 Navigation Controller ,在“Show the Attributes Inspector”中禁用 Shows Navigation Bar。
回答by drew..
in my particular case, the place to call into a subset of views that required a push was only from code and was not connectable via IB. The original project to create the subset of views was started with a dedicated button and thus was IB'able.
在我的特定情况下,调用需要推送的视图子集的位置仅来自代码,无法通过 IB 连接。创建视图子集的原始项目是从一个专用按钮开始的,因此是 IB'able。
No segue was configurable, and thus any push resulted in this error.
没有 segue 是可配置的,因此任何推送都会导致此错误。
My solution was simple: [self showViewController:targetViewController sender:self];
我的解决方案很简单:[self showViewController:targetViewController sender:self];
回答by Shashwat
if you are using UIViewController class
如果您使用 UIViewController 类
then check one thing in the declaration of segue identifier for example, you have set
然后在 segue 标识符的声明中检查一件事,例如,您已经设置
Identifier:MySegue1 Segue:Present Modally (choose this if you are using UIViewController Class)
Identifier:MySegue1 Segue:Present Modally(如果您使用 UIViewController 类,请选择此项)
Presentation: Default Transition: Default
演示文稿:默认 过渡:默认
and check one more thing that your object deceleration is correct
并检查您的对象减速是否正确的另一件事
Maybe my answer is not exactly correct,but this is what all i get to know abut this error. hope it will help you lil bit.
也许我的答案不完全正确,但这就是我所知道的关于这个错误的全部信息。希望它会帮助你一点点。
回答by bdv
I had the same problem as you had.
我和你有同样的问题。
My problem was that I was calling the identifier of a segue that wasn't accessible from within the class I was calling the segue from. I solved it by adding another segue directly to the view from the ViewController that had access to the class I was working in. Hope this helps.
我的问题是我正在调用无法从我调用 segue 的类中访问的 segue 的标识符。我通过从可以访问我正在使用的类的 ViewController 中直接向视图添加另一个 segue 来解决它。希望这会有所帮助。
回答by Singh
If your application has navigation controller as root view controller of window ,select storyboard file and then select the corresponding navigation controller , in Simulated Metrics select Is Initial View Controller checkbox. This worked for me. Hope this helps.
如果您的应用程序将导航控制器作为窗口的根视图控制器,请选择故事板文件,然后选择相应的导航控制器,在模拟指标中选择是初始视图控制器复选框。这对我有用。希望这可以帮助。
回答by Narasimha Nallamsetty
I have faced same problem after few minutes I could solve it.
几分钟后我遇到了同样的问题,我可以解决它。
I have deleted segue connections and I have made connections again from one view to other views.That's it the problem is solved. the thing is I have deleted views and I have made few changes to the views in story board scene. And important thing is you need to check connections working properly from one view to another view.
我已经删除了 segue 连接,并且我再次从一个视图到另一个视图建立了连接。这样问题就解决了。问题是我删除了视图,并且对故事板场景中的视图做了一些更改。重要的是您需要检查从一个视图到另一个视图的连接是否正常工作。
This may be helpful to some one I hope....
这可能对我希望的人有所帮助......