注:组件化之后 发现原来的资源都无法正常的加载了 问题的原因就是路径发生了改变 所以想正确的加载资源 必须把路径修改正确
一.图片资源路径
以WKWebTest
//stringName 就是你图片资源的名字
- (UIImage*)setResourcesPath:(NSString*)stringName {
//------------------路径
NSURL *urlClassBundle = [[NSBundle bundleForClass:[self class]] URLForResource:@"WKWebTest" withExtension:@"bundle"];
NSBundle*urlBundle = [NSBundlebundleWithURL:urlClassBundle];
UIImage *image = [UIImage imageNamed:stringName inBundle:urlBundle compatibleWithTraitCollection:nil];
returnimage;
}
二.storyboard路径
- (UIViewController*)loadStoryboard:(UIViewController*)viewController {
//获取pods中的路径
NSBundle*currentBundle = [NSBundlebundleForClass:[viewControllerclass]];
NSURL*bundleUrl = [currentBundleURLForResource:@"SXLoginCompont"withExtension:@"bundle"];
NSBundle *dle = [NSBundle bundleWithURL:bundleUrl];
//storyboardv创建
UIStoryboard *mainStoryBoard = [UIStoryboard storyboardWithName:@"SXLogin" bundle:dle];
return [mainStoryBoard instantiateViewControllerWithIdentifier:@"SXLoginViewController"];
}
三.xib路径
下面简易的写了下 具体用法按照自己实际怎么用就怎么写
UINib *loadNib = [UINib nibWithNibName:@"SXLogin" bundle:dle];
return [_tableView registerNib:loadNib forCellReuseIdentifier:@"这里写cell的Identifierin"];