ios - 无法转换视图控制器的值错误
问题描述
我的应用程序一直运行良好,直到今天在成功构建后突然出现以下错误:
Could not cast value of type 'FirebaseApp.HomeViewController' (0x101ab6aa0) to 'FirebaseApp.MenuViewController' (0x101ab6d30).
Could not cast value of type 'FirebaseApp.HomeViewController' (0x101ab6aa0) to 'FirebaseApp.MenuViewController' (0x101ab6d30).
我的应用程序委托中的行
让控制器 = storyboard.instantiateViewController(withIdentifier: "mainView") as!菜单视图控制器
然后在此 AppDelegate 类中以红色突出显示:
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
FirebaseApp.configure()
// Override point for customization after application launch.
let authListener = Auth.auth().addStateDidChangeListener { auth, user in
let storyboard = UIStoryboard(name: "Main", bundle: nil)
if user != nil {
//
let controller = storyboard.instantiateViewController(withIdentifier: "MainTabBarController") as! UITabBarController
self.window?.rootViewController = controller
self.window?.makeKeyAndVisible()
} else {
// main screen
let controller = storyboard.instantiateViewController(withIdentifier: "mainView") as! MenuViewController
self.window?.rootViewController = controller
self.window?.makeKeyAndVisible()
}
}
return true
}
我有一个 HomeViewController
类 HomeViewController:UIViewController, UITableViewDelegate, UITableViewDataSource {
其中有我的大部分代码。
我不确定这里出了什么问题,但我怀疑这与我的故事板中的错误命名有关。
编辑:我通过将“mainView”更改为“MenuViewController”解决了这个问题
解决方案
推荐阅读
- node.js - EB AWS 上的错误 - 502 Bad Gateway nginx/1.18.0
- r - aes_string() 是否更改 R 中的任何默认设置?R Shiny 和 ggplot input$ 交互的问题
- python - 在 .env 文件上打印 key=value 对
- java - 需要exe文件才能打开控制台
- vim - 如何使用 coc-clangd 在 vim 中使用 lib gtk 在 C 中编程?
- javascript - 无法使用 chartjs 绘制饼图 - 类型错误:无法在数字“16”上创建属性“_meta”
- python - 我希望我的立方体可重复性在 pygame 中每秒的每一帧都向前移动,但我不知道出了什么问题?
- java - 在不为第二个数组分配空间的情况下从已排序的数组中删除重复项
- python - 在第三行显示局部变量 L 已分配但从未使用过
- javascript - 使用 Cloudflare Worker 进行部署的问题