在自定义Cocoapods中使用Storyboard和Image资源

我试图用cocoa豆荚模块化一个大的iOS项目(在Swift中开发)。 这个想法是创build“子应用程序”,可以集成到主要项目中的故事板和资产。

在这种情况下,我遇到了使用故事板的麻烦。 这个问题类似于(我认为): https : //github.com/CocoaPods/CocoaPods/issues/2597

这里是我试图转换成pod的模块的.podspec:

Pod::Spec.new do |spec| spec.name = 'GlycoAppMenuModule' spec.version = '0.0.8' spec.license = { :type => 'MIT', :file => 'LICENSE' } spec.homepage = 'https://google.com' spec.platform = :ios, "8.0" spec.authors = { 'Abdulla Contractor' => 'abdulla.contractor@gmail.com' } spec.summary = 'Views for menu page' spec.source = { :git => 'https://github.com/Holmusk/GlycoAppMenuModule.git', :tag => '0.0.8' } spec.source_files = 'GlycoAppMenuModule/*' spec.resource_bundles = { 'resources' => ['GlycoAppMenuModule/**/*.{lproj,storyboard}']} # spec.framework = 'Foundation' end 

这里是我用来试图使用故事板的代码

 let bundlePath = NSBundle(forClass: GANavigationMenuViewController.self).pathForResource("resources", ofType: "bundle") let bundle = NSBundle(path: bundlePath!) let storyboard: UIStoryboard = UIStoryboard(name: "Menu", bundle: bundle) let vc = storyboard.instantiateInitialViewController() as! UIViewController self.presentViewController(vc, animated: false, completion: nil) 

这是我得到的错误

 2015-06-05 11:39:40.365 temp[3593:50802] Unknown class _TtC9resources30GANavigationMenuViewController in Interface Builder file. 2015-06-05 11:39:40.370 temp[3593:50802] Could not load the "icAccount.png" image referenced from a nib in the bundle with identifier "(null)" 2015-06-05 11:39:40.371 temp[3593:50802] Could not load the "icConnect.png" image referenced from a nib in the bundle with identifier "(null)" 2015-06-05 11:39:40.371 temp[3593:50802] Could not load the "icDiabetesProfile.png" image referenced from a nib in the bundle with identifier "(null)" 2015-06-05 11:39:40.373 temp[3593:50802] Could not load the "icLogout.png" image referenced from a nib in the bundle with identifier "(null)" 2015-06-05 11:39:40.377 temp[3593:50802] Could not load the "icCircle.png" image referenced from a nib in the bundle with identifier "(null)" 2015-06-05 11:39:40.386 temp[3593:50802] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UIViewController 0x7fb3f3d2cdd0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key accountButton.' 

任何想法,我可能会失踪?

我有同样的问题,我解决了。

在您的.podspec中,您需要的唯一资源标签是:

 s.resources = "MMA_Piece/**/*.{png,jpeg,jpg,storyboard,xib,xcassets}" 

现在你可能会问:“当然我已经试过了,但是没有用,为什么现在要工作?”

那么让我告诉你:D

确保您希望包含在您的自定义CocoaPod中的每个资源都在您的底层项目目录中。 在我的情况下(MMA_Piece项目)这是以下文件夹(所选的一个):

在这里输入图像说明

完成! 如果您使用“pod install”在另一个项目中使用pod,则资源将如下所示:

在这里输入图像说明

重要提示:如果您想在其他项目中使用资源,请说“MainProject”,您将始终需要指定捆绑包! 或“MainProject”将无法find资源!

希望这可以帮助你!