1

I am new to iOS app development and currently facing some issues segueing from a UIButton to a UIViewController. I did above in Main.storyboard by:

  • selecting UIButton
  • holding "control" and dragging to UIViewController
  • Selecting "push" under Action Segue

After running this, i get below 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.'

Need help on resolving above error. Would appreciate it if solution comes with screenshots since i'm a newbie. Thanks!

After implementing @technerd solution, it still does not work. Below are images of the Navigation Controller menu and Action Segue Menu

enter image description here

enter image description here

  • As said: You can do a Push, only if you have a UINavigationController (the bar at the top that you can see on many apps to illustrate). Else, it's a Show, not a Push. – Larme Feb 28 '18 at 16:23
  • Under Action Segue, i have only 3 options: Push, Modal, Custom. There is no Show – Pascal Okyere Adomako Feb 28 '18 at 16:28
  • Modal then. Note that the behavior is different because the context is. Also, you are using an Old version of XCode? – Larme Feb 28 '18 at 16:30
  • I am using Version 9.2 (9C40b) – Pascal Okyere Adomako Feb 28 '18 at 16:38
  • Possible duplicate of [NSGenericException', reason: 'Push segues can only be used when the source controller is managed by an instance of UINavigationController](https://stackoverflow.com/questions/13546122/nsgenericexception-reason-push-segues-can-only-be-used-when-the-source-contr) – theCoderGuy Feb 28 '18 at 16:55

3 Answers3

2

From error logs it looks like you have not embedded UINavigationController as initial controller in you storyboard.

So first set UINavigationController as initial controller. Because push and pop operation only performed when there is Navigation stack available.

  1. Select first ViewController in Storyboard as per screen shot.
  2. Then Editor -> EmbedIn -> NavigationController

To know how Navigation Stack works, go through this link.

enter image description here

Once you set Navigation as InitialViewController, then set your first viewcontroller you want to show first as rootViewController of that navigation controller.

enter image description here

Then you can drag push from button to secondViewController to push from firstViewController to secondViewController.

enter image description here

As you can read in screenshot that Push(Deprecated), so you have to use Show relationship. Show also perform same operation as Push.

Update :

As per your question update, you are facing that you are not able to show other Action Segue. Follow below steps to make it available.

  1. Select your Navigation Controller in storyboard.
  2. Enable Use Trait Variations option under Interface Builder Document on right side panel.

enter image description here

For more details check this thread.

technerd
  • 14,144
  • 10
  • 61
  • 92
0

Add Navigation Controller to your initial view

  1. Select the initial view
  2. Go To Editor--> Embed In --> Navigation Controller.
Rashed
  • 2,349
  • 11
  • 26
0

Push segues are only available in UINavigationController types. Try to add UINavigationController. An easy way is:

enter image description here

Mina
  • 2,167
  • 2
  • 25
  • 32