Yrb
Yrb

Reputation: 9755

Button Activated Segue Not Being Called

I have a strange problem. I have two segues triggered by buttons in a table view controller, which is the root view controller of a navigation controller. One segue will trigger, and the other will not. They are from two different buttons, with two different identifiers.

I put a breakpoint inside prepare(for segue: UIStoryboardSegue, sender: Any) and I can verify that the second button is not calling it. Any ideas would be appreciated.

My code is:

    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        if segue.identifier == "locationViewSegue", let destinationViewController = segue.destination as? LocationViewController  {
            destinationViewController.delegate = self
            destinationViewController.weatherData = self.weatherData
            destinationViewController.wxObservationStationsArray = self.wxObservationStationsArray
            destinationViewController.newCoordinates = self.weatherData.locationCoordinates
        } else if segue.identifier == "searchPriorLocations", let destinationViewController = segue.destination as? SearchBarTableViewController  {
            destinationViewController.priorForecastLocations = self.priorForecastLocations

        }
    }

My Storyboard follows with the offending segue highlighted: Storyboard

Any thoughts on this would be appreciated.

Upvotes: 0

Views: 1381

Answers (1)

matt
matt

Reputation: 535999

I have two segues triggered by buttons

I'm going to suggest that in fact no, you don't. One of the segues is perhaps triggered by a button; that's the one that works as you expect — the segue fires when the button is tapped. But the other segue, though it exists, does not emanate from the other button; it emanates from the cell or from the view controller as a whole.

The way to check this is to select the button and display the Connections Inspector:

enter image description here

If you don't see that — an "action" triggered segue associated with the button — tapping the button won't fire the segue.

Upvotes: 3

Related Questions