ios - 为什么在我的框架中我可以访问 Storyboard_a.storyboard 而无法访问 Storyboard_b.storyboard?

标签 ios swift frameworks storyboard cocoapods

我有一个包含两个 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 中,因为:

  1. 在 myFramework 构建阶段的“复制捆绑资源”下,我可以看到它们都包含在内。
  2. 在 myFramework.framework 中,我可以看到:StoryBoard_A.storyboardc 和 StoryBoard_B.storyboardc
  3. 当我“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/

相关文章:

ios - Apple、iOS 13、CryptoKit、Secure Enclave - 在使用私钥之前强制执行生物识别身份验证

javascript - iOS Safari 显示来自 .toLocaleString() 和 .slice() 的不同数据

ios - 在 swift (IOS) 中将模式 TableView 中的值返回到主 TableView

swift - 为什么在传递给具有可选类型的函数参数时强制使用 nil 的 uwrapped 类型不会崩溃?

ios - 如何镜像或翻转 CVImageBuffer

php - 独立路由库?

unit-testing - Tibco 单元测试工具

php - 如何在 PHP 中的请求之间持久化对象

ios - 崩溃异常: NSInvalidArgumentException -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[1]

ios - 如何在 UIView 中安排动态创建的 UILabels?