I want to segue from a tableview that is embedded in a navigation controller to another view controller once I clicked on a table cell. I still want that second view controller to be embedded in the same navigation controller. Hence, I created the segue via storyboard.
However, I want to conditionally check after tapping on the cell if the segue should be performed or not.
I already checked out the method shouldPerformSegueWithIdentifier, which would satisfy my needs, but unfortunately, it is executed before the table click handler. If I remove the storyboard segue and just segue via performSegue, my second view controller is not embedded in the same navigation controller anymore.
Any advice?
Here's my code:
// Called on click event on table cell
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: true)
let app = apps[indexPath.section]
if app.state == .INSTALLED {
let inputVC = self.navigationController?.viewControllers[1] as? InputVC
inputVC?.app = app
performSegue(withIdentifier: "showAccSync", sender: self)
} else {
// show alert
}
}


shouldPerformSegueis what you want; but you shouldn't then have any code indidSelectRowAt, or you can ctrl-drag from the orange view controller object in your scene to your next scene and then perform that segue usingperformSegueindidSelectRowAt- Paulw11inputVCfrom the navigation controller throws me an out of bounds though - phoebusprepareForSegue- Paulw11prepareFor:function. The destination view controller doesn't exist before you have calledperformSegue- Paulw11