问题
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
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?
Thanks
回答1:
add Navigation Controller to your initial view
- Select the initial view
- Go To Editor--> Embed In --> Navigation Controller.
回答2:
Set UINavigationcontroller as Initial View controller (Initial Scene) in StoryBoard.
回答3:
In my case at the time the original VC performed the segue, the Navigation Controller was transitioning and already changed he visible VC.
I solved it by doing:
if (self.navigationController.visibleViewController == self) {
[self performSegueWithIdentifier:@"thankyou" sender:self];
}
no more crash. :)
回答4:
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.
Hope this helps.
回答5:
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.
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.
回答6:
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.
No segue was configurable, and thus any push resulted in this error.
My solution was simple: [self showViewController:targetViewController sender:self];
回答7:
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.
回答8:
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.
This may be helpful to some one I hope....
回答9:
I have faced same problem and I searched a lot but nothing could help me. I tried in many ways.Finally I found solution. I am doing a project in xcode 5 and developed views using story board. I have 3 screens and my connections are..
view1 to view2-->push
view2 to view3-->push
view2 to view1-->modal(this is my mistake we need to use push only)
this is fine working well but I have placed bar button item(Back) in view2 and segue connection was modal . when I click on view2 bar button it is redirected to view1 properly but when I try to go ahead from view1 to view2 I got the same error. Because if you give push segue type from source view to destination view you need to use same push segue from destination view to source view..
I hope it will be helpful to someone..thanks
回答10:
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.
回答11:
if you are using UIViewController class
then check one thing in the declaration of segue identifier for example, you have set
Identifier:MySegue1 Segue:Present Modally (choose this if you are using UIViewController Class)
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.
来源:https://stackoverflow.com/questions/13546122/nsgenericexception-reason-push-segues-can-only-be-used-when-the-source-contr