Luc
Luc

Reputation: 53

Could not cast value of type 'UINavigationController' Error

I am having an issue with swift 3 when I am trying to connect a Slide out Menu to another ViewController but I am getting an issue with the prepareforsegue.

Here is my code.

override func prepare(for segue: UIStoryboardSegue, sender: Any?)
 {        
    let DestVC = segue.destination as! ViewControllerSlide

Here is where I am getting my error. ^^^

    var indexPath : IndexPath = self.tableView.indexPathForSelectedRow!
    
    DestVC.varView = indexPath.row 
}

Upvotes: 1

Views: 2455

Answers (1)

Tj3n
Tj3n

Reputation: 9923

Probably your segue is pointing to an UINavigationController, try assign the destination with that first:

let destVC = segue.destination as! UINavigationController
let slideVC = destVC.topViewController as! ViewControllerSlide
//...

Upvotes: 7

Related Questions