在cocoapods中加载resource_bundle错误 [英] Loading resource_bundle error in cocoapods
本文介绍了在cocoapods中加载resource_bundle错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试制作自己的椰壳动物,我使用了图像。
当我按照本教程进行操作时,出现错误。
I am trying to make my own cocoapods, I used images. When I follow the tutorial, I get an error.
.podspec
s.resource_bundles = {
'SSSlidingSelector' => ['SSSlidingSelector/Assets/*.xcassets']
}
Class / SlidingSelector.m
- (UIImage *)getImageWithName:(NSString *)imageName {
NSBundle *bundle = [NSBundle bundleForClass:[self class]];
NSURL *url = [bundle URLForResource:@"SSSlidingSelector" withExtension:@"bundle"];
NSBundle *targetBundle = [NSBundle bundleWithURL:url];
UIImage *image = [UIImage imageNamed:imageName
inBundle:targetBundle
compatibleWithTraitCollection:nil];
return image;
}
错误
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSBundle initWithURL:]: nil URL argument'
屏幕截图
Screenshot
我的代码有什么问题?
thks
What is wrong with my code? thks
推荐答案
- (UIImage *)getImageWithName:(NSString *)imageName {
NSBundle *bundle = [NSBundle bundleForClass:[self class]];
UIImage *image = [UIImage imageNamed:imageName
inBundle:bundle
compatibleWithTraitCollection:nil];
return image;
}
这篇关于在cocoapods中加载resource_bundle错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文