5
self?.performSegue(withIdentifier: "myview", sender: nil)

Above code do not show the navigation bar even though I use push in storyboard. Below code is shows me an error, even though the segue with correct name exist

self?.navigationController?.performSegue(withIdentifier: "myview", sender: nil)

Error

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Receiver () has no segue with identifier 'myview''

MGY
  • 7,245
  • 5
  • 41
  • 74
cole
  • 3,147
  • 3
  • 15
  • 28
  • In what class are you trying to do this, what does `self` refer to? Are you sure you set up the segue identifier correctly? – Dávid Pásztor Aug 16 '17 at 10:18
  • yes, that's why simple self?.performSegue works but no navigation bar. And the navigation one is throws an error – cole Aug 16 '17 at 10:23
  • Thanks, as everyone suggested there was no viewcontroller when i was making the self?.navigationController?.performSegue. – cole Aug 16 '17 at 10:44

6 Answers6

4

Your navigation bar might be hidden, try adding this code in viewcontroller which get called by the segue

override func viewWillAppear(_ animated: Bool) {
    self.navigationController?.setNavigationBarHidden(false, animated: true)
}

Note: Please check the viewController pushing the segue with "myView" is embeded in UINavigationController .

pkamb
  • 33,281
  • 23
  • 160
  • 191
Preeti Rani
  • 685
  • 7
  • 17
3

self?.navigationController?.performSegue(withIdentifier: "myview", sender: nil) The segue is attached to a UIViewController subclass instance and not to a UINavigationController instance, so you cannot call it on the latter.

If you don't have a navigation bar after performing a segue, you have to make sure that you properly embedded your view controller in a navigation controller or if you added the navigation bar manually, make sure you add it to your other view controller as well in the viewWillAppear method.

Dávid Pásztor
  • 51,403
  • 9
  • 85
  • 116
2

In case 1 : make sure the visibility on UINavigationBar.

In case 2 : connect segue with UINavigationController not with UIViewController.

enter image description here

pkamb
  • 33,281
  • 23
  • 160
  • 191
Nauman Malik
  • 1,326
  • 9
  • 27
1

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Receiver (<UINavigationController: 0x1180a2e00>) has no segue with identifier 'myview''

As simply as written in the Error, no segue is named 'myView', depending if you're using the storyboard, you should take a look here Without the story board, check that

but moreover, take time to read error message.

Keuha
  • 295
  • 3
  • 18
0
self?.navigationController?.performSegue(withIdentifier: "myview", sender: nil)

This line will not perform the segue with myview. You have attached the segue with the view controller not the navigation controller. That's why you are getting the error while doing this.

self?.performSegue(withIdentifier: "myview", sender: nil)

Check if you have properly attached the view controller to segue and make sure you are having an attached navigation controller with your view controller. if you push directly without navigation controller attached to it, it will cause issues.

Hope it solves the problem. If it doesn't then please update the answer when you find the solution. Thanks!

Ankur JAIN
  • 111
  • 8
0

I had an issue where presenting a new VC via a segue was showing only a white screen with no navigation bar visible. It seemed like the Navigation Controller was somehow being ignored.

Turns out the app had a strange color pallet set via code like:

UINavigationBar.appearance().tintColor = .white

Giving the new VC a background color showed that the navigation bar and controller were actually there, just all blended together in white.

tint color

pkamb
  • 33,281
  • 23
  • 160
  • 191