无法将 'UINavigationController' 类型的值转换为 'jacrs_ios.TopViewController'
Could not cast value of type 'UINavigationController' to 'jacrs_ios.TopViewController'
我是 Swift 的新手,我试图根据我正在学习的教程制作侧边菜单,但我 运行 遇到了这个错误。 "Could not cast value of type 'UINavigationController' (0x1026054a8) to 'jacrs_ios.TopViewController' (0x1009ac510)." 我注意到这里已经存在同样的问题,但我还是不明白。我将包括当前的情节提要,以防我做错了什么。谢谢
ViewController错误
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
let topViewController = segue.destination as! TopViewController
topViewController.stringPassed = userName.text!
}
故事板
试试这个
if let navigationController = segue.destination as? UINavigationController
{
let topViewController = navigationController?.topViewController as! TopViewController
topViewController.stringPassed = userName.text!
}
我是 Swift 的新手,我试图根据我正在学习的教程制作侧边菜单,但我 运行 遇到了这个错误。 "Could not cast value of type 'UINavigationController' (0x1026054a8) to 'jacrs_ios.TopViewController' (0x1009ac510)." 我注意到这里已经存在同样的问题,但我还是不明白。我将包括当前的情节提要,以防我做错了什么。谢谢
ViewController错误
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
let topViewController = segue.destination as! TopViewController
topViewController.stringPassed = userName.text!
}
故事板
试试这个
if let navigationController = segue.destination as? UINavigationController
{
let topViewController = navigationController?.topViewController as! TopViewController
topViewController.stringPassed = userName.text!
}