【问题标题】:fix the error -> "Could not cast value of type 'SecondViewController' to 'FirstViewController'"修复错误->“无法将'SecondViewController'类型的值转换为'FirstViewController'”
【发布时间】:2018-12-13 17:38:13
【问题描述】:

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

我有 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, +)
    }

这是我的 StoryBoard 的图片:

感谢您的宝贵时间!

【问题讨论】:

  • 看起来 let firstTabVC = ((self.tabBarController?.viewControllers![0] as! UINavigationController).viewControllers[0]) 实际上返回了 CartViewController

标签: ios swift uitabbarcontroller uistoryboard


【解决方案1】:

在我使用拖放交换这 2 个图标后,我在一秒钟内修复了此错误。

感谢您的宝贵时间!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-09-05
    • 1970-01-01
    • 2020-08-04
    • 2019-10-12
    • 2020-05-09
    • 1970-01-01
    • 2019-11-28
    相关资源
    最近更新 更多