2015-06-05 19 views
9

Sto provando a modulare un grande progetto iOS (in fase di sviluppo in Swift) utilizzando i pod di cacao. L'idea è di creare "subapp" complete di storyboard e risorse che potrebbero essere integrate nel progetto principale.Utilizzo di storyboard e risorse immagine in Cocoapod personalizzati

Sto avendo problemi con gli storyboard in uno scenario del genere. Il problema è simile a (credo): https://github.com/CocoaPods/CocoaPods/issues/2597

Ecco la .podspec del modulo che sto cercando di convertire in un baccello:

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' => '[email protected]' } 
    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 

e qui è il codice che uso per tentare di utilizzare lo storyboard

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) 

questo è l'errore che ottengo

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.' 

Qualche idea di cosa possa mancare?

+0

Sembra un problema simile http://stackoverflow.com/questions/3088059/che-segue-questo-mano-nsunknownkeyexception-reasonthis-class-is-not-key-valu –

risposta

3

Ho avuto lo stesso problema e l'ho risolto.

Nella tua .podspec tag unica risorsa che vi serve è:

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

Ora si potrebbe chiedere:? "Certo che ho già provato questo, ma non ha funzionato perché dovrebbe funzionare ora? "

Beh lasciate che vi dica: D

assicurarsi che ogni risorsa che si desidera avere incluso nella vostra abitudine CocoaPod è all'interno della vostra directory del progetto di livello inferiore. Nel mio caso (progetto MMA_Piece) questo è il seguente cartella (quella selezionata):

enter image description here

Fatto! Se si utilizza il pod in un altro progetto, utilizzando 'pod install' le risorse saranno venire con esso in questo modo:

enter image description here

IMPORTANTE: Se si desidera utilizzare la risorsa in altro progetto, dire "MainProject", devi SEMPRE per specificare il pacchetto! Oppure "MainProject" non sarà in grado di trovare la risorsa!

Spero che questo ti aiuti!

+1

Grazie mille! Ho cercato per ore e finalmente trovato, che stranamente ho bisogno di usare non un 'spec.resource_bundles' (ha creato un altro target, e non sarò in grado di recuperare bundle da esso", ma un 's.resources'. *RABBIA* –

Problemi correlati