1. 圖片的內(nèi)存優(yōu)化
兩種加載圖片的方法,各有優(yōu)點和缺點。
imageNamed:這個方法加載完圖片后,圖片會駐留內(nèi)存,壞處:占用內(nèi)處,好處:調(diào)用速度很快
imageWithContentsOfFile:這個方法當(dāng)圖片用完后回釋放內(nèi)存,好處:不占用內(nèi)存,性能比較好,壞處:速度慢.
2. NSBundle
1> 一個NSBundle代表一個文件夾,利用NSBundle能訪問對應(yīng)的文件夾
2> 利用mainBundle就可以訪問軟件資源包中的任何資源
3> 模擬器應(yīng)用程序的安裝路徑
/Users/aplle/資源庫/Application Support/iPhone Simulator/7.1/Applications
3. Xcode文檔安裝路徑
/Applications/Xcode.app/Contents/Developer/Documentation/DocSets
4. Xcode模擬器安裝路徑
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs
5. 隱藏導(dǎo)航欄
- (BOOL)prefersStatusBarHidden{
return YES;
}
6. instancetype
instancetype在類型表示上,跟id一樣,可以表示任何對象類型
instancetype只能用在返回值類型上,不能像id一樣用在參數(shù)類型上
instancetype比id多一個好處:編譯器會檢測instancetype的真實類型
7. Xib文件的加載
方法1
NSArray *objs = [[NSBundle mainBundle] loadNibNamed:@"MJAppView" owner:nil options:nil];
這個方法會創(chuàng)建xib中的所有對象,并且將對象按順序放到objs數(shù)組中
(如果xib如右圖所示,那么objs數(shù)組中依次會有3個對象:1個UIView、1個UIButton、1個UISwitch)
方法2
bundle參數(shù)可以為nil,默認就是main bundle
UINib *nib = [UINib nibWithNibName:@"MJAppView" bundle:[NSBundle mainBundle]];
NSArray *objs = [nib instantiateWithOwner:nil options:nil];
在開發(fā)階段,面向開發(fā)者的是xib文件; 當(dāng)把應(yīng)用裝到手機上時,xib文件就會轉(zhuǎn)為nib文件
8. Xib和storyboard對比
共同點:
都用來描述軟件界面
都用Interface Builder工具來編輯
不同點
Xib是輕量級的,用來描述局部的UI界面
Storyboard是重量級的,用來描述整個軟件的多個界面,并且能展示多個界面之間的跳轉(zhuǎn)關(guān)系
9. Xcode頭文件
1).Xcode自帶頭文件的路徑
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator8.1.sdk/System/Library/Frameworks/UIKit.framework/Headers
2).修改了系統(tǒng)自帶頭文件后,Xcode會報錯
解決方案:刪掉下面文件夾的緩存即可(aplle是電腦的用戶名)
/Users/aplle/資源庫/Developer/Xcode/DerivedData
或者
/Users/aplle/Library/Developer/Xcode/DerivedData
10. 封裝創(chuàng)建View的代碼, 讓用戶不知道是通過xib創(chuàng)建的還是通過代碼創(chuàng)建的,安全,擴展性比較好。
- 封裝一個類方法
+ (instancetype )loadNib{
return [[NSBundle mainBundle]loadNibNamed:@"appView" owner:nil options:nil][0];
}