cole
cole

Reputation: 3357

self?.performSegue is not showing navigation bar

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''

Upvotes: 5

Views: 2332

Answers (6)

pkamb
pkamb

Reputation: 35002

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

Upvotes: 0

Nauman Malik
Nauman Malik

Reputation: 1346

In case 1 : make sure the visibility on UINavigationBar.

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

enter image description here

Upvotes: 2

Preeti Rani
Preeti Rani

Reputation: 695

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 .

Upvotes: 4

David Pasztor
David Pasztor

Reputation: 54745

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.

Upvotes: 3

Ankur JAIN
Ankur JAIN

Reputation: 121

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!

Upvotes: 0

Keuha
Keuha

Reputation: 295

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.

Upvotes: 1

Related Questions