无法将“UINavigationController"类型的值转换为“jacrs_ios.TopViewController" [英] Could not cast value of type 'UINavigationController' to 'jacrs_ios.TopViewController'

查看:25
本文介绍了无法将“UINavigationController"类型的值转换为“jacrs_ios.TopViewController"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Swift 的新手,我试图根据我遵循的教程制作侧边菜单,但我遇到了这个错误.无法将‘UINavigationController’(0x1026054a8)类型的值转换为‘jacrs_ios.TopViewController’(0x1009ac510)."我注意到这里已经存在相同的问题,但我仍然不明白.如果我做错了什么,我将包括当前的故事板.谢谢.

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.

视图控制器错误

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!

}

这篇关于无法将“UINavigationController"类型的值转换为“jacrs_ios.TopViewController"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆