我有一个包含两个故事板的框架: StoryBoard_A.storyboard和StoryBoard_B.storyboard。我可以联系到StoryBoard_A,但StoryBoard_B不能
我在我的主要项目中使用我的框架作为吊舱。在我的框架podspec文件中有:
s.source_files = "myFramework/**/*.{swift}"
s.resource_bundles = { 'myFramework' => ['myFramework/**/*.{storyboard,xib,xcassets}'] }我知道两个故事板都在myFramework包中,因为:
在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该应用程序在第二行崩溃,有以下错误:
*终止应用程序由于非正常异常'NSInvalidArgumentException',原因:‘找不到一个故事板名为'StoryBoard_B’在捆绑.
我遗漏了什么?
谢谢
发布于 2019-05-07 14:08:46
我发现了这个问题:因为这是我继承的一段代码,我试图将它合并到myFramework中,所以我不知道在ViewController_b.swift (我试图从故事板中启动的代码)中有这样一个事实:
var storyboard = UIStoryboard(name: "Stroyboard_B", bundle: nil)在课堂范围内。
我将此更改为我创建的包,其方式与上面描述的相同,从而解决了问题。
在成功地尝试从这个故事板启动其他ViewControllers之后,我发现了这一点。这让我看了看ViewController_b内部,看看它比其他视图控制器更适合。
发布于 2019-05-07 03:12:31
右击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!)https://stackoverflow.com/questions/56013061
复制相似问题