ios - 您如何调用/使用位于子项目中的 Storyboard

标签 ios uiviewcontroller storyboard swift3 uistoryboard

我在我的 Xcode 项目中添加了一个子项目,并将其添加为目标依赖项。我现在想在位于该子项目的 Storyboard 中使用 View Controller 。我想知道这是否可能以及如何将 View Controller 从该子项目实例化到您的主项目中。

打电话

let storyboard = UIStoryboard(name: "Calculator", bundle: nil)
let calculatorViewController = storyboard.instantiateViewController(withIdentifier: "calculatorViewController") as! CalculatorViewController
self.present(calculatorViewController, animated: false, completion: nil)

由于“计算器” Storyboard 在子项目中,因此不起作用。我正在使用 swift 3。

最佳答案

我认为问题在于 Calculator Storyboard不在主包中。当您传入 nil 时,运行时会尝试在此处查找它。对于 UIStoryboard 中的捆绑包初始化器。

如果您为 Storyboard 中包含的类之一传入捆绑包,可能会起作用:

let storyboard = UIStoryboard(name: "Calculator", bundle: Bundle(for: calculatorViewController.self))

关于ios - 您如何调用/使用位于子项目中的 Storyboard ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41244754/

相关文章:

ios - 替换 iOS 中保留的 "description"的字段的适当名称是什么?

c# - 消息 AOT 问题 Attempting to JIT compile method with Pinvoke on Xamarin iOS

ios - MSSync表插入

ios - iOS swift UITouch 移动不稳定

iOS - 未调用警报 View 的 segue

IOS/objective-C/ Storyboard : Custom Segue from Left to Right Creating Black Bar Between View Controllers

objective-c - 在 Subview 或 ViewController 中处理触摸事件逻辑

ios - iOS 在显示之前如何设置 ViewController View 框架?

ios - UIScrollView 和 Storyboard

ios - 当 Xcode 自发调整 Storyboard时,有没有人让它真的破坏了任何东西?