2019-03-18 sdk中的bundle资源加载方式

1:先找主资源
NSBundle *bundle = [NSBundle bundleForClass:[self class]]或者[NSBundle mainBundle]
2:找主bundle中的指定bundle
可以断点获取path 通过查找文件夹前往 查看bundle中是否包含资源

NSString *bundlePath = [[NSBundle mainBundle] pathForResource:@"QNJSDK" ofType:@"bundle"];
NSBundle *bundle = [NSBundle bundleWithPath:bundlePath];
3:找bundle中的指定资源
NSString *nibPath = [bundle pathForResource:@"QNJCreditProductCell" ofType:@"nib"];
4:使用资源
①:UINib *nib = [UINib nibWithNibName:@"QNJCreditProductCell" bundle:bundle];
②:[tableView registerNib:[UINib nibWithNibName:@"QNJCreditProductCell" bundle:bundle] forCellReuseIdentifier:@"QNJCreditProductCell"];
③:QNJCreditProductCell *cell = [[bundle loadNibNamed:@"QNJCreditProductCell" owner:nil options:nil] lastObject];


当获取不到资源时 可前往bundle内部查看

5:注意事项
要把图片、xib引进资源库

xib在bundle中以nib结尾

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。