当尝试使用 instantiateViewController(withIdentifier:)
从 Storyboard实例化 View Controller 时,Xcode 会抛出此错误:
typeMismatch(Swift.Array, Swift.DecodingError.Context(codingPath: [], debugDescription: "Expected to decode Array but found a dictionary instead.", underlyingError: nil))
我怀疑这是在最近的 Swift 补丁之后开始发生的。回退到旧的提交也不能解决问题。我能够从同一个 Storyboard实例化其他 View Controller ,但特别是那个 View Controller 总是抛出此错误。
我尝试重命名 View Controller 的标签,从同一 Storyboard实例化不同的 View Controller (这是成功的),并清理项目
let vc = storyBoard.instantiateViewController(withIdentifier: "map") as! ViewController
self.present(vc, animated: true, completion: nil)
最佳答案
我发现了错误。如果其他人在尝试实例化 View Controller 时出错,则实例化的类将运行其初始代码行。我假设如果它实际上调用 View Controller ,它会调用 viewDidLoad,但它只会初始化函数上方的所有变量。
关于ios - 实例化 View Controller 时出现类型不匹配错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58532288/