ios - 实例化 View Controller 时出现类型不匹配错误

标签 ios swift xcode storyboard

当尝试使用 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/

相关文章:

swift - IndexArray 超出范围,具有默认的 collectionviewcells 数量

ios - CGBitMapContextCreate 方法导致编译器警告 Xcode 5 而不是 Xcode 4

ios - ViewControl 之外的 Swift 选择器

ios - Trigger.io forge.topbar.setTint() 错误

iphone - objective-c : Do I have to retype all the code everytime?

ios - 我的代码中出现 NSInternalInconsistencyException 错误

swift - 模式 : Using a default value when optional is nil

ios - 加载应用程序时无法获取位置,但从另一个 View Controller 传递时

ios - setContentOffset 从 ScrollView 的底部开始不起作用

ios - 为什么我在 Objective C 中获取 NSString 的值,例如 0xb000000000000033