为什么我的框架能达到Storyboard_a.storyboard而不能达到Storyboard_b.storyboard?
Why can I reach Storyboard_a.storyboard and fail to reach Storyboard_b.storyboard in my framework?
我有一个包含两个故事板的框架: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}'] }
我知道两个故事板都在 myFramework 包中,因为:
- 在 myFramework Build Phases 的 Copy Bundle Resources 下,我可以看到它们都包含在内。
- 在myFramework.framework中我可以看到:StoryBoard_A.storyboardc和StoryBoard_B.storyboardc
- 当我 'pod install' myFramework 作为开发 pod 时,我可以在主项目的项目导航器中看到两个故事板
在 myFramework 中,我从 ViewController_1 开始 ViewController_a 从 StoryBoard_A.storyboard 开始 ViewController_b 从 StoryBoard_B.storyboard 开始。
我使用相同的技术:
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 个文件是否 present.If 个文件不存在,您有不同的问题需要解决。
如果文件存在,请尝试如下所示访问它。
let podBundle = Bundle(forClass: ViewController_1.self)
let bundleURL = podBundle.resourceURL?.URLByAppendingPathComponent("myFramework.bundle")
let resourceBundle = Bundle(URL: bundleURL!)
我发现了问题:
因为这是我继承的一段代码,我试图将它合并到 myFramework 中,所以我不知道 ViewController_b.swift(我试图从故事板启动的那个)里面有:
var storyboard = UIStoryboard(name: "Stroyboard_B", bundle: nil)
在 class 范围内。
我将其更改为按照上述相同方式创建的捆绑包并解决了问题。
我在成功尝试从此故事板启动其他 ViewController 后发现了这一点。这让我深入了解 ViewController_b 以了解它比其他视图控制器有何延迟
我有一个包含两个故事板的框架: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}'] }
我知道两个故事板都在 myFramework 包中,因为:
- 在 myFramework Build Phases 的 Copy Bundle Resources 下,我可以看到它们都包含在内。
- 在myFramework.framework中我可以看到:StoryBoard_A.storyboardc和StoryBoard_B.storyboardc
- 当我 'pod install' myFramework 作为开发 pod 时,我可以在主项目的项目导航器中看到两个故事板
在 myFramework 中,我从 ViewController_1 开始 ViewController_a 从 StoryBoard_A.storyboard 开始 ViewController_b 从 StoryBoard_B.storyboard 开始。 我使用相同的技术:
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 个文件是否 present.If 个文件不存在,您有不同的问题需要解决。
如果文件存在,请尝试如下所示访问它。
let podBundle = Bundle(forClass: ViewController_1.self)
let bundleURL = podBundle.resourceURL?.URLByAppendingPathComponent("myFramework.bundle")
let resourceBundle = Bundle(URL: bundleURL!)
我发现了问题: 因为这是我继承的一段代码,我试图将它合并到 myFramework 中,所以我不知道 ViewController_b.swift(我试图从故事板启动的那个)里面有:
var storyboard = UIStoryboard(name: "Stroyboard_B", bundle: nil)
在 class 范围内。
我将其更改为按照上述相同方式创建的捆绑包并解决了问题。
我在成功尝试从此故事板启动其他 ViewController 后发现了这一点。这让我深入了解 ViewController_b 以了解它比其他视图控制器有何延迟