2019-03-18 sdk中的bundle资源加载方式
2019-03-18 本文已影响0人
惊蛰_e3ce
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结尾