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结尾
网友评论