修复错误 -> "Could not cast value of type 'SecondViewController' to 'FirstViewController'"

fix the error -> "Could not cast value of type 'SecondViewController' to 'FirstViewController'"

今天我拆分了我的故事板,现在我收到一个错误,我不知道如何修复它。

我有 1 个故事板(产品),其中包含第一个选项卡中的所有 UIViewController,还有另一个故事板(购物车),其中包含第二个选项卡中的所有 UIViewController。 我已经将 StoryBoard 入口点设置为所有导航控制器,我在 MainStoryboard 中设置了引用,我为每个 StoryBoard 引用设置了正确的故事板目标,我真的不知道我做错了什么。

这是我在启动应用程序时遇到的错误:

"Could not cast value of type 'ShoppingLand.CartViewController' (0x10d72a780) to 'ShoppingLand.ProductsViewController' (0x10d72a8c0)."

这是我的函数崩溃的地方(在第一行崩溃):

// Append the selectedProducts into productsInCartArray using the TabBarController
    func fetchSelectedProducts() {
        let firstTabVC = ((self.tabBarController?.viewControllers![0] as! UINavigationController).viewControllers[0] as! ProductsViewController)
        productsInCartArray = firstTabVC.selectedProductsArray
        productPricesArray = firstTabVC.priceForSelectedProductsArray
        getProductsPhotosArray = firstTabVC.googlePhotosArray
        totalSum = productPricesArray.reduce(0, +)
    }

这是我的 StoryBoards 的照片:

感谢您的宝贵时间!

我使用拖放交换了这 2 个图标后,很快就修复了这个错误。

感谢您的宝贵时间!