我有一个包含两个 Storyboard的框架:StoryBoard_A.storyboard 和 StoryBoard_B.storyboard。 我可以访问 StoryBoard_A,但不能访问 StoryBoard_B
我在我的主项目中使用我的框架作为 Pod。 在我的框架 podspec 文件中,我有:
s.source_files = "myFramework/**/*.{swift}"
s.resource_bundles = { 'myFramework' => ['myFramework/**/*.{storyboard,xib,xcassets}'] }
我知道两个 Storyboard都在 myFramework bundle 中,因为:
- 在 myFramework 构建阶段的“复制捆绑资源”下,我可以看到它们都包含在内。
- 在 myFramework.framework 中,我可以看到:StoryBoard_A.storyboardc 和 StoryBoard_B.storyboardc
- 当我“pod install”myFramework 作为开发 pod 时,我可以在主项目的项目导航器中看到两个 Storyboard
在 myFramework 中,我从 ViewController_1 启动来自 StoryBoard_A.storyboard 的 ViewController_a 和来自 StoryBoard_B.storyboard 的 ViewController_b。 我使用相同的技术:
let podBundle = Bundle(for: ViewController_1.self)
let bundleURL = podBundle.url(forResource: "myFramework", withExtension: "bundle")
let bundle = Bundle(url: bundleURL!)!
let storyBoard = UIStoryboard(name: "StoryBoard_A", bundle: bundle)
let viewController_a = storyBoard.instantiateViewController(withIdentifier: "ViewController_a_id") as? ViewController_a
但是当我这样做时:
let storyBoard = UIStoryboard(name: "StoryBoard_B", bundle: bundle)
let viewController_b = storyBoard.instantiateViewController(withIdentifier: "ViewController_b_id") as? ViewController_b
应用程序在第二行崩溃,并出现以下错误:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Could not find a storyboard named 'StoryBoard_B' in bundle...
我错过了什么?
谢谢
最佳答案
在 Xcode 中的“产品”下右键单击您的应用程序,然后在 Finder 中浏览它。只需检查 StoryBoard_B.storyboardc 文件是否存在。如果文件不存在,则需要解决不同的问题。
如果文件存在,请尝试按如下所示访问它。
let podBundle = Bundle(forClass: ViewController_1.self)
let bundleURL = podBundle.resourceURL?.URLByAppendingPathComponent("myFramework.bundle")
let resourceBundle = Bundle(URL: bundleURL!)
关于ios - 为什么在我的框架中我可以访问 Storyboard_a.storyboard 而无法访问 Storyboard_b.storyboard?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56013061/