Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 无法强制转换视图控制器的值错误_Ios_Swift_Xcode - Fatal编程技术网

Ios 无法强制转换视图控制器的值错误

Ios 无法强制转换视图控制器的值错误,ios,swift,xcode,Ios,Swift,Xcode,我的应用程序构建得很好,直到今天,我在成功构建后突然出现以下错误: Could not cast value of type 'FirebaseApp.HomeViewController' (0x101ab6aa0) to 'FirebaseApp.MenuViewController' (0x101ab6d30). Could not cast value of type 'FirebaseApp.HomeViewController' (0x101ab6aa0) to 'Fireba

我的应用程序构建得很好,直到今天,我在成功构建后突然出现以下错误:

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.InstanceEviewController标识符: 主视图为!菜单控件

然后在此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{

其中包含了我大部分的代码

我不确定这里出了什么问题,但我怀疑这与我的故事板中的错误命名有关

编辑:我通过在MenuViewController的序列图像板中将mainView更改为MenuViewController解决了这个问题。您需要将mainView设置为序列图像板ID,而不是还原ID

如下图所示:


让controller=storyboard.instantiationeviewcontrollerwhidentifier:mainView as!MenuViewController-此行返回HomeViewController,但您强制将类型转换为MenuViewController,请检查故事板中的viewController标识符您的屏幕截图显示的是视图,而不是视图控制器。您在故事板中查看的位置错误.