按钮激活的Segue没有被调用

时间:2017-01-06 14:25:37

标签: ios swift segue

我有一个奇怪的问题。我有两个由表视图控制器中的按钮触发的segue,它是导航控制器的根视图控制器。一个segue将触发,另一个不会触发。它们来自两个不同的按钮,有两个不同的标识符。

我在prepare(for segue: UIStoryboardSegue, sender: Any)内放了一个断点,我可以验证第二个按钮没有调用它。任何想法,将不胜感激。

我的代码是:

    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

        }
    }

我的故事板跟随突出的segue突出显示: Storyboard

对此的任何想法都将不胜感激。

1 个答案:

答案 0 :(得分:3)

  

我有两个由按钮触发的segue

我会建议事实上不,你不是。 一个的segue可能是由按钮触发的;这是一个按预期工作的 - 当点击按钮时,segue会触发。但另一个segue虽然存在但并非来自另一个按钮;它来自单元格或视图控制器整体。

检查方法是选择按钮并显示Connections Inspector:

enter image description here

如果你没有看到 - 一个"动作"触发与按钮相关联的segue - 点击按钮不会触发segue。