【发布时间】:2018-08-16 15:09:44
【问题描述】:
我创建了一个包含使用 CocoaPod 的 xib 视图的新框架,以及一个用于测试该框架的测试应用程序。测试应用程序包含一个调用该框架并显示 xib 的按钮。
起初我在这一行的框架内发生了崩溃:
if let myView = Bundle.main.loadNibNamed("myCustomXib", owner: self, options: nil)?.first as? myCustomXibClass
日志:Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle </Users/User/Library/Developer/CoreSimulator/Devices/F7B870D5-4CEC-4CC7-9C76-75DF1408A26C/data/Containers/Bundle/Application/20E3D273-315C-43EE-95CC-9B00B8EE8B6E/appDemo.app> (loaded)' with name 'myCustomXib''
然后我用这个改变了那行:
let bundle = Bundle(identifier:"com.framework.identifier")
if let myView = bundle?.loadNibNamed("myCustomXib", owner: self, options: nil)?.first as? myCustomXibClass {
崩溃消失了,但没有显示任何内容。
这是我在 podspec 中添加源代码的方式:
s.resources = ["**/*.{storyboard,xib}", "Assets.xcassets"]
我得到了本地开发 pod 中的所有文件。故事板完美地工作,但不是 xib。那我该怎么办?
【问题讨论】:
-
有人遇到过这个问题吗?
-
嗨,你得到了上述解决方案。
-
听起来你是从“Development Pods”目录本地运行你的代码,如果是这样使用CMD+SHIFT+K生效
标签: ios swift cocoa-touch xib