问题
I'm new to Swift and I was trying to make a side menu base on the tutorial that I was following but I ran across with this error. "Could not cast value of type 'UINavigationController' (0x1026054a8) to 'jacrs_ios.TopViewController' (0x1009ac510)." I noticed that there were same problems already existing here but I still dont understand. I'm gonna included the current storyboard in case I did something wrong. Thanks.
ViewController Error
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
let topViewController = segue.destination as! TopViewController
topViewController.stringPassed = userName.text!
}
Storyboard
回答1:
Try this
if let navigationController = segue.destination as? UINavigationController
{
let topViewController = navigationController?.topViewController as! TopViewController
topViewController.stringPassed = userName.text!
}
来源:https://stackoverflow.com/questions/45688834/could-not-cast-value-of-type-uinavigationcontroller-to-jacrs-ios-topviewcontr