Passing data with segue through navigationController

The destination view controller of the segue is the UINavigationController. You need to ask it for its top view controller to get to the real destination view controller:

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    if segue.identifier == "showItemSegue" {
        let navController = segue.destination as! UINavigationController
        let detailController = navController.topViewController as! ShowItemViewController
        detailController.currentId = nextId!

Leave a Comment