0. 網(wǎng)絡(luò)含有很多有關(guān)iOS封裝framework .a靜態(tài)庫(kù)文章旦棉,本文推薦
iOS靜態(tài)庫(kù)
iOS打包framework靜態(tài)庫(kù)
1. 總結(jié)
bundle中存放圖片,xib药薯,storyboard等資源文件
### 獲取NSBundle方法有2種
法一:
#define Bundle_IN_Framework [NSBundle bundleWithPath:[[NSBundle mainBundle] pathForResource:@"你的bundle的名字" ofType:@"bundle"]]
法二:
#define Bundle_IN_Framework [NSBundle bundleWithPath:[[NSBundle bundleForClass:[self class]].resourcePath stringByAppendingPathComponent:@"/封裝的bundle的名字.bundle"]]
【Storyboard】
#define StoryBoard_Name(@"你使用的storyboard名字") [UIStoryboard storyboardWithName:@"你使用的storyboard名字" bundle: Bundle_IN_Framework];
【圖片】
#define ImageNamed(@"圖片的名字") [UIImage imageNamed:@"圖片的名字" inBundle: Bundle_IN_Framework compatibleWithTraitCollection:nil]
【xib】
#define Nib_Name(@"你的nib名字") [UINib nibWithNibName:@"你的nib名字" bundle: Bundle_IN_Framework]
使用
self.img.image = ImageNamed(@"圖片名字");
viewController *vc = [StoryBoard_Name(@"Main") instantiateViewControllerWithIdentifier: "storybord中的ID"];
[tableView registerNib:Nib_Name(@"你的nib名字") forCellReuseIdentifier:@"復(fù)用Identifier"];
2.錯(cuò)誤
- 在靜態(tài)庫(kù)中寫了一個(gè)XXViewController類绑洛,然后在主工程的xib中,將xib的類指定為XXViewController童本,程序運(yùn)行時(shí)真屯,報(bào)了如下錯(cuò)誤:
Unknown class XXViewController in Interface Builder file.
其實(shí)這個(gè)問(wèn)題與Interface Builder無(wú)關(guān),最直接的原因還是相關(guān)的symbol沒(méi)有從靜態(tài)庫(kù)中加載進(jìn)來(lái)穷娱。這種問(wèn)題的處理就是在Target的“Build Setting
”–>“Other Link Flags
”中加上-all_load
和-ObjC
這兩個(gè)標(biāo)識(shí)位绑蔫,這樣就OK了。