? ? ? 工作了兩年多,一直有個(gè)“壞習(xí)慣”垒酬,就是將工作中遇到的一些問題砰嘁、技巧或心得記在印象筆記里面,按理來說勘究,作為一個(gè)開發(fā)者矮湘,要擁抱開源精神,將這些美好的東西分享給大家乱顾,或許能夠幫助別人解決問題或是引起少許的共鳴板祝。
? ? ? 簡書給我的第一印象是:風(fēng)格清新,易用走净,同時(shí)也是一個(gè)不錯(cuò)的交流技術(shù)券时,交流心得的好平臺(tái),趁最近在找工作的空檔伏伯,抽些時(shí)間將印象筆記里面的tips橘洞、輪子或技術(shù)解決方案移到這里來。
? ? ? ?翻了一下印象筆記的筆記本说搅,咋一看嚇一跳炸枣,將近一千條筆記!!适肠! 根據(jù)80 20 法則霍衫,怎么也有200條對一部分人是有參考意義的。這里抽取200條比較有價(jià)值的筆記分享出來侯养,希望看完博客的看官能夠有所收獲敦跌。
? ? ? PS:因?yàn)橛行﹖ips是在一個(gè)swift項(xiàng)目中收集下來的,所以下面放出的tip既有Objective-C 也有 Swift逛揩。由于有些筆記記錄的是iOS 6.0時(shí)代的一些問題柠傍,因此可能存在一些錯(cuò)誤的地方,歡迎指正辩稽。
tip 1 : ?給UIImage添加毛玻璃效果
func blurImage(value:NSNumber) -> UIImage {
? ? ? let context = CIContext(options:[KCIContextUseSoftwareRenderer:true])
? ? ? let ciImage = CoreImage.CIImage(image:self)
? ? ? let blurFilter = CIFilter(name:"CIGassianBlur")
? ? ? blurFilter?.setValue(ciImage, forKey:KCIInputImageKey)
? ? ? blurFilter?.setValue(value, forKey:"inputRadius")
? ? ? let imageRef = context.createCGImage((blurFilter?.outputImage)!, fromRect:(ciImage?.extent)!)
? ? ?let newImage = UIImage(CGImage:imageRef)
? ? ?return newImage
}
value : value代表毛玻璃效果的程度
核心內(nèi)容:let blurFilter = CIFilter(name:"CIGassianBlur") 使用濾鏡工具
tip 2 : 圖片壓縮
func imageCompress(targetWidth:CGFloat) -> UIIMage {
? ? ? ? let targetHeight = targetWidth/width*height
? ? ? ?UIGraphicsBeginImageContext(CGSizeMake(targetWidth,targetHeight))
? ? ? self.drawInRect(CGRectMake(0,0,targetWidth,targetHeight))
? ? ? let newImage:UIImage = UIGraphicsGetImageFromCurrentImageContext()
? ? ? UIGrapicsEndImageContext()
? ? ? return newImage
}
這里是按原UIImage比例做壓縮所以:let targetHeight = targetWidth/width*height
tip 3 : SVN & Git 用法總結(jié)
一:SVN
A. 項(xiàng)目經(jīng)理:1.創(chuàng)建項(xiàng)目—CheckIn
2.設(shè)置項(xiàng)目人員
B.工作人員:1.CheckOut 獲取項(xiàng)目的完整副本惧笛,此工作只需要做"一次"
2. 工作寫代碼....
3.階段性工作完成后,Commit(提交) 將自己修改的文件逞泄,上傳到服務(wù)器
每天下班前一定要做一次能夠編譯的提交患整!
4.定期Update項(xiàng)目,從服務(wù)器將最新的內(nèi)容更新到本地炭懊,每天上班第一件事情一定要做的事情并级!
二. Git
A.項(xiàng)目經(jīng)理:1.創(chuàng)建項(xiàng)目push
2.設(shè)置項(xiàng)目人員
B. 工作人員:1.Pull從服務(wù)器下拉最新的本版
2.Commit是將修改過的代碼提交至本地的代碼庫
3.每天下班前Push自己當(dāng)前的代碼到服務(wù)器
4.每天上班前從服務(wù)器Pull最新的內(nèi)容
三. M / A 文件更新
對于文件夾svn支持并不好拂檩,需要在工具下選定文件夾commit
對應(yīng)文件選定文件commits
由于過去在公司多半時(shí)間是做獨(dú)立開發(fā)侮腹,最多人的時(shí)候也是兩個(gè)人做開發(fā),所以協(xié)作工具用的少稻励,但是不斷的關(guān)注著兩種代碼倉庫管理工具父阻,總結(jié)了一些tip,還有待實(shí)踐驗(yàn)證望抽,吐槽吧......
tip 4: ?UINavigationController下的坐標(biāo)系
iOS 9 前:
navigationBar 如果設(shè)置了背景圖片加矛,那么可視化坐標(biāo)會(huì)從navgationbar下面開始
self.navigationController?.navigationBar.setBackgroundImage(UIImage(named:"nav"), forBarMetrics:UIBarMetrics.Default)
iOS 9 后 : 坐標(biāo)從狀態(tài)欄下面開始
tip 5 : C字符串轉(zhuǎn)成NSString &? NSString轉(zhuǎn)成C字符串
const char *cString = "CString";
C字符串轉(zhuǎn)成NSString : NSString *str = [NSString stringWithUTF8String:cString];
NSString * str = @"NSString";
NSString轉(zhuǎn)成C字符串 : const char *cString = [str UTF8String];
tip 6 : OC & Swift 代碼塊(語法糖)
Objective-C :
UILabel *label1 = ({
? ? ? ?UILabel *label = [UILabelnew];
? ? ? ?[self.view addSubview:label];
? ? ? ?label.frame=CGRectMake(100,100,100,45);
? ? ? ?label.backgroundColor= [UIColor redColor];
? ? ? ?label.text=@"大家好1";
? ? ? label;
});
UILabel*label2 = ({
? ? ? ?UILabel*label = [UILabel new];
? ? ? ?[self.view addSubview:label];
? ? ? ?label.frame=CGRectMake(100,160,100,45);
? ? ? ?label.backgroundColor= [UIColor redColor];
? ? ? ?label.text=@"大家好2";
? ? ? ?label;
});
UILabel*label3 = ({
? ? ? ?UILabel*label = [UILabel new];
? ? ? ?label.frame=CGRectMake(100,250,100,45);
? ? ? ?label.backgroundColor= [UIColor redColor];
? ? ? ?label.text=@"大家好3";
? ? ? ?label;
});
[self.viewaddSubview:label3];
({
? ? ? ?UILabel *label = [UILabel new];
? ? ? ?[self.view addSubview:label];
? ? ? ?label.frame=CGRectMake(100,310,100,45);
? ? ? ?label.backgroundColor= [UIColor redColor];
? ? ? ?label.text=@"大家好4";
});
Swift:
letlabel1:UILabel= {
? ? ? ? let label =UILabel()
? ? ? ? self.view.addSubview(label)
? ? ? ? label.frame=CGRectMake(100,100,100,45)
? ? ? ? label.backgroundColor=UIColor.redColor()
? ? ? ? label.text="大家好"
? ? ? ?return label
}()
let label2:UILabel= {
? ? ? let label =UILabel()
? ? ? label.frame=CGRectMake(100,200,100,45)
? ? ? label.backgroundColor=UIColor.redColor()
? ? ? label.text="大家好"
? ? ? return label
}()
self.view.addSubview(label2)
使用語法糖的好處就是拷貝代碼時(shí)只需做少許的修改就可以達(dá)到目的,如上面的栗子煤篙,想要?jiǎng)?chuàng)建多個(gè)label斟览,只要賦值粘貼,改一處辑奈,也就是對象名稱就可以輕松完成苛茂!
tip 7 : 數(shù)據(jù)持久化方式歸納總結(jié)
數(shù)據(jù)緩存方式選擇:
1: fmdata數(shù)據(jù)庫(增刪改查) ? --數(shù)據(jù)需要:增刪改查
2: coreData ? ? ? ? ? ? ? ? ? ? ? ? --數(shù)據(jù)需要:增刪改查
3:序列化(NSUserDefault) ? ?--狀態(tài)、偏好設(shè)置鸠窗、默認(rèn)選項(xiàng)
4:單獨(dú).plist ? ? ? ? ? ? ? ? ? ? ? ? --列表數(shù)據(jù),城市信息等
5:單獨(dú).json文件 ? ? ? ? ? ? ? ? ?--頁面列表數(shù)據(jù)
6: realm框架(增刪改查) ? ? ? --數(shù)據(jù)需要:增刪改查
7:? FastCoder ?某“強(qiáng)哥”推薦妓羊,哈哈哈!
tip 8 : 清理Profiles證書文件
~/Library/MobileDevice/Provisioning Profiles
由于平時(shí)會(huì)負(fù)責(zé)多個(gè)項(xiàng)目的上線管理或是開發(fā)工作稍计,因此MAC中有很多簽名文件躁绸,有時(shí)候都分不清東西南北,一不做,二不休净刮,前往這個(gè)目錄下剥哑,將文件刪個(gè)精光,調(diào)試的時(shí)候用到證書再update一下當(dāng)前項(xiàng)目的證書即可
tip 9 : 拿到當(dāng)前屏幕所看到的viewController
Objective-c版本:
- (UIViewController *)getAppRootViewController
{
? ? ? ?UIViewController *appRootVC = [UIApplication sharedApplication].keyWindow.rootViewController;
? ? ? ?UIViewController *topVC = appRootVC;
? ? ? ?while (topVC.presentedViewController) ?{
? ? ? ? ? ? ?topVC = topVC.presentedViewController;
? ? ? ?}
? ? ? ?return topVC;
Swift版本:
func getAppRootViewController()?->?UIViewController??{
? ? ? ?var?topVC?=?UIApplication.sharedApplication().keyWindow?.rootViewController
? ? ? ?while topVC?.presentedViewController?!=?nil?{
? ? ? ? ? ? ? topVC?=?topVC?.presentedViewController
? ? ? ?}
? ? ? ?return topVC?
}
tip 10 : 制作pch文件
步驟:
1淹父、新建iOS->Other->PCH File
2星持、targets->BuildSetting->Prefix Header->設(shè)置$(SRCROOT)/文件在工程中的路徑
3、pch能像以前一樣正常使用
如:$(SRCROOT)/FirstProject/PrefixHeader.pch
FirstProject : pch路徑中的最后一個(gè)拓展名
PrefixHeader.pch: 是pch文件名
簡介:/Users/ly/Desktop/FirstProject/FirstProject
tip 11 : ?設(shè)置UINavigationController title
當(dāng) UIViewController作為UINavigationController的根視圖控制器的時(shí)候弹灭,將這個(gè)Nav(root)賦給 tabBarController時(shí)督暂,
這樣寫:
root.title = @“title”;
那么 :self.naviagtionItem.title 會(huì)顯示 title
同時(shí) :nav.tabBarItem.title 也會(huì)顯示 ?title
tip 12 : 判斷UIScrollView是橫向滾動(dòng)還是豎向滾動(dòng)
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer*)gestureRecognizer {
? ? ? ? ?if([gestureRecognizerisKindOfClass:[UIPanGestureRecognizerclass]]) {
? ? ? ? ? ? ? ?CGPointvelocity = [(UIPanGestureRecognizer*)gestureRecognizervelocityInView:gestureRecognizer.view];
? ? ? ? ? ? ? ?BOOLisHorizontalPanning =fabsf(velocity.x) >fabsf(velocity.y);
? ? ? ? ? ? ? ?return isHorizontalPanning;
? ? ? ? }
? ? ? returnYES;
}
tip 13 : 監(jiān)聽? backBarButtonItem 返回事件
github上搜: UIViewController+BackButtonHandler 開源項(xiàng)目
tip 14 : 讓一個(gè)view透明度失效
self.view.backgroundColor=UIColor(colorLiteralRed:255.0/255, green:255.0/255, blue:255.0/255, alpha:0.3)
let subView = UIView()
subView.tintColor=UIColor.whiteColor()//不透明了
self.view.addSubview(subView)
tip 15 : 從ipod庫中讀出音樂文件
// 從ipod庫中讀出音樂文件
MPMediaQuery?*everything?=?[[MPMediaQuery?alloc]?init];
//?讀取條件
MPMediaPropertyPredicate?*albumNamePredicate?=?[MPMediaPropertyPredicate?predicateWithValue:[NSNumber?numberWithInt:MPMediaTypeMusic]?forProperty:?MPMediaItemPropertyMediaType];
[everything?addFilterPredicate:albumNamePredicate];
NSLog(@"Logging?items?from?a?generic?query...");
NSArray?*itemsFromGenericQuery?=?[everything?items];
for?(MPMediaItem?*song?in?itemsFromGenericQuery)?{
? ? ? NSString?*songTitle?=?[song?valueForProperty:?MPMediaItemPropertyTitle];
? ? ? ?NSLog?(@"%@",?songTitle);
}
tip 16 : 廣告標(biāo)示符(adId) & adfv標(biāo)示符的那些事
1.如何識(shí)別一個(gè)應(yīng)用安裝在同一個(gè)設(shè)備上呢?
2.如何識(shí)別一個(gè)企業(yè)的應(yīng)用安裝在同一個(gè)設(shè)備上呢穷吮?
蘋果給我們提供了advertisingIdentifier 來解決問題1逻翁;
只要是同一臺(tái)設(shè)備,那么advertisingIdentifier就是一樣的
但是如果在設(shè)置-隱私-廣告那里關(guān)掉這個(gè)權(quán)限或是還原設(shè)備的話捡鱼,就沒辦法了哭死去吧
蘋果給我們提供了identifierForVendor 來作為一個(gè)企業(yè)的app標(biāo)示符
比如: com.game.yoyo
com.game.xoxo
只要在同一臺(tái)設(shè)備上八回,那么identifierForVendor 是一樣的
如果:com.game.yoyo
com.buyer.yoyo
不管是不是同一個(gè)應(yīng)用identifierForVendor 都是不一樣的
上代碼:
廣告id:
#import
//每個(gè)設(shè)備有唯一一個(gè),如果重置廣告或設(shè)置-隱私-關(guān)閉廣告就會(huì)關(guān)閉更換
NSString*adId = [[[ASIdentifierManagersharedManager]advertisingIdentifier]UUIDString];
企業(yè)id:
NSString*idfv = [[[UIDevicecurrentDevice]identifierForVendor]UUIDString];
tip 17 : 不使用JPush等的原始推送
一步一步教你做ios推送 - 有夢想的蝸牛 - 博客頻道 - CSDN.NET
推送通知iOS客戶端編寫實(shí)現(xiàn)及推送服務(wù)器端編寫 - OPEN 開發(fā)經(jīng)驗(yàn)庫
由于簡書的一些限制驾诈,不能粘貼文件缠诅,考慮選擇一個(gè)方式將我自己的實(shí)踐工程放出來,以后持續(xù)更新
(MAC下搭建服務(wù)器+證書制作+推送測試)
tip 18 : 設(shè)置系統(tǒng)音量(排版有段亂乍迄,將就一下(⊙﹏⊙)b)
#import"VolumeSetter.h"
#import
@implementationVolumeSetter
{
MPVolumeView*volumeView;
UISlider* volumeViewSlider;
}
+ (instancetype)shareInstance
{
staticVolumeSetter*vs;
staticdispatch_once_tonce;
dispatch_once(&once, ^{
vs = [[VolumeSetteralloc]init];
});
returnvs;
}
- (void)setVolume:(float)value
{
[self getSlider];
[volumeViewSlidersetValue:valueanimated:NO];// send UI control event to make the change effect right now.
[volumeViewSlidersendActionsForControlEvents:UIControlEventTouchUpInside];
}
- (float)getVolume:(volumeBlock)handel
{
_myHandel= handel;
[selfgetSlider];
returnvolumeViewSlider.value;
}
- (MPVolumeView*)getVolumeView
{
if(volumeView==nil) {
volumeView= [[MPVolumeViewalloc]init];
[[NSNotificationCenterdefaultCenter]addObserver:self
selector:@selector(volumeChanged:)
name:@"AVSystemController_SystemVolumeDidChangeNotification"
object:nil];
}
returnvolumeView;
}
- (UISlider*)getSlider
{
[selfgetVolumeView];
for(UIView*viewin[volumeViewsubviews]){
if([view.class.descriptionisEqualToString:@"MPVolumeSlider"]){
volumeViewSlider= (UISlider*)view;break;
}
}
returnvolumeViewSlider;
}
- (void)volumeChanged:(NSNotification*)notification
{
floatvolume =
[[[notificationuserInfo]
objectForKey:@"AVSystemController_AudioVolumeNotificationParameter"]
floatValue];
NSLog(@"current volume = %f", volume);
_myHandel(volume);
}
@end
tip 19 : 提高開發(fā)效率 開發(fā)工具(轉(zhuǎn))
http://www.cocoachina.com/ios/20151110/14102.html
tip 20 : XMPP 開發(fā)與服務(wù)器搭建
待補(bǔ)充
tip 21 :? 設(shè)置UINavigationItem 返回按鈕 和 back title
1. push 之前
// back title
self.navigationItem.backBarButtonItem=UIBarButtonItem(title:"返回", style:UIBarButtonItemStyle.Plain, target:nil, action:nil)
// 特別注意:在push之前設(shè)置
self.navigationController?.pushViewController(vc, animated:true)
2.設(shè)置顏色
self.navigationController?.navigationBar.tintColor=UIColor.blackColor()
總結(jié):
self.navigationItem.backBarButtonItem=UIBarButtonItem(title:"返回", style:UIBarButtonItemStyle.Plain, target:nil, action:nil)
self.navigationController?.navigationBar.tintColor=UIColor.blackColor()
self.navigationController?.pushViewController(vc, animated:true)
tip 22 : ?語法風(fēng)格
Swift : https://github.com/raywenderlich/swift-style-guide#use-of-self
?OC : https://github.com/raywenderlich/objective-c-style-guide
tip 23 : 謂詞
Person類:
@interfacePerson :NSObject
@property(nonatomic) NSUIntager age;
@property(nonatomic,copy)NSString*name;
@end
#import"Person.h"
@implementationPerson
- (NSString*)description
{
return[NSStringstringWithFormat:@"age=%d,name=%@",self.age,self.name];
}
@end
ViewController.m類:
Person*p1 = [[Personalloc]init];
p1.age=15;
p1.name=@"張三";
Person*p2 = [[Personalloc]init];
p2.age=25;
p2.name=@"小米";
Person*p3 = [[Personalloc]init];
p3.age=15;
p3.name=@"李四";
NSArray*arr =@[p1,p2,p3];
//謂詞
NSPredicate*pre = [NSPredicatepredicateWithFormat:@"%K==%d || %K==%@ || %K=%@",@"age",15,@"name",@"張三",@"name",@"李四"];
arr = [arrfilteredArrayUsingPredicate:pre];
NSLog(@"%@",arr);
輸出:
2015-12-08 11:24:05.862 Predicate[12080:634959] (
"age=15,name=\U5f20\U4e09",
"age=15,name=\U674e\U56db"
)
用于做查詢操作非常棒管引,避免寫一大堆的if else操作
tip 24 : Xcode 插件
?VVDocumenter 是一個(gè)比較好用的注釋控件
Alcatraz(插件管理器)http://www.tuicool.com/articles/v2eIVb
https://github.com/supermarin/Alcatraz
Xcode 6.4找不到packageManager :http://blog.csdn.net/yimu520csdn/article/details/47040041
tip 25 : 微信登錄,分享等 不執(zhí)行代理方法
方法一:
- (BOOL)application:(UIApplication*)application handleOpenURL:(NSURL*)url
{
? ? ? ? return [WXApihandle OpenURL:urldelegate:self];
}
方法二:
- (BOOL)application:(UIApplication*)application openURL:(NSURL*)url sourceApplication:(NSString*)sourceApplication annotation:(id)annotation
{
? ? ? ? return[WXApihandle OpenURL:url delegate:self];
}
今天做微信登陸功能闯两,隨手寫一個(gè)demo褥伴,沒有設(shè)置bundle id , display name,結(jié)果就不走 方法一漾狼,方法二
導(dǎo)致下面兩個(gè)代理方法不走
- (void) onReq:(BaseReq*)req{
? ? ? ? NSLog(@"xxxxxxxx");
}
- (void) onResp:(BaseResp*)resp{
? ? ? ? NSLog(@"fffffffff");
}
解決方法:設(shè)置Bundle identifier 以及 Bundledisplayname 重慢,注意要與注冊獲取appid secret key 時(shí)所填的保持一致.
當(dāng)然其他設(shè)置也要保證設(shè)置上,比如 URL sechme , iOS9 注意適配 ATS,添加白名單
tip 26 :? iOS7.0后隱藏狀態(tài)欄(UIStatusBar)
現(xiàn)象:
升級(jí)到iOS7后逊躁,UIStatusBar的出現(xiàn)導(dǎo)致現(xiàn)有UI界面亂掉了似踱。
原因:
由于寫死了某些控件的絕對位置,原先隱藏UIStatusBar的代碼沒有在iOS7中起作用
解決方法:
iOS7以下版本隱藏UIStatusBar的方法:
-?(BOOL)application:(UIApplication*)applicationdidFinishLaunchingWithOptions:(NSDictionary*)launchOptions
{
? ? ? ?[application setStatusBarHidden:YES];
? ? ? ?returnYES;
}
升級(jí)到iOS7后的方法:
在基類中重載UIViewController.h中的這個(gè)方法
-?(BOOL)prefersStatusBarHidden?NS_AVAILABLE_IOS(7_0);//?Defaults?to?NO
-?(BOOL)prefersStatusBarHidden
{
? ? ? return YES;
//?iOS7后以下方法已經(jīng)不起作用: ? [[UIApplication?sharedApplication]?setStatusBarHidden:YES?withAnimation:UIStatusBarAnimationFade];
}
tip 27 : UIColor 轉(zhuǎn) RGB
UIColor*color = [UIColorcolorWithRed:0.0green:0.0blue:1.0alpha:1.0];
constCGFloat*components =CGColorGetComponents(color.CGColor);
NSLog(@"Red: %f", components[0]);
NSLog(@"Green: %f", components[1]);
NSLog(@"Blue: %f", components[2]);
tip 28 : ?摳圖 & 合成圖片 (轉(zhuǎn))
iOS開發(fā)-簡單圖片背景替換(實(shí)現(xiàn)摳圖效果)
http://www.tuicool.com/articles/VZN3yiZ
tip 29 :? Mac 生成UUID 命令: uuidgen
在命令行工具輸入 $ uuidgen : 8-4-4-4-12
tip 30 : ?23種設(shè)計(jì)模式
https://github.com/huang303513/Design-Pattern-For-iOS
tip 31 :? 發(fā)布APP要求
發(fā)布APP要求稽煤,不能使用Beta版本的Xcode
如果一個(gè)開發(fā)團(tuán)隊(duì)里面有多個(gè)小伙伴核芽,不要為了嘗新將所有的Mac OX 或是Xcode都升級(jí)到Beta版本,應(yīng)該由一個(gè)小伙伴進(jìn)行測試感受新版本是否穩(wěn)定念脯,是否有坑狞洋,否定后果很嚴(yán)重,說多都是淚绿店,您想想:重新裝系統(tǒng)吉懊,重新下載Xcode是一件多么苦逼的事情庐橙。。借嗽。
?
tip 32 : UIScrollView 判斷是向左滾動(dòng)還是向右滾動(dòng)
這是抄自項(xiàng)目里面的一段代碼态鳖,如果您要用到判斷UIScrollView向左還是向右的滾動(dòng)邏輯,請先定義相關(guān)狀態(tài)的全局變量
-(void)scrollViewWillBeginDragging:(UIScrollView*)scrollView
{
? ? ? ? ? ? startContentOffsetX= scrollView.contentOffset.x;
}\
- (void)scrollViewWillEndDragging:(UIScrollView*)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inoutCGPoint*)targetContentOffset{//將要停止前的坐標(biāo)
? ? ? ? ? ?willEndContentOffsetX= scrollView.contentOffset.x;
}
- (void)scrollViewDidEndDecelerating:(UIScrollView*)scrollView{
? ? ? ?endContentOffsetX= scrollView.contentOffset.x;
? ? ? ?if(endContentOffsetX < willEndContentOffsetX && willEndContentOffsetX < startContentOffsetX) {
? ? ? ? ? ? ? ?NSLog(@"畫面從右往左移動(dòng)恶导,前一頁");
? ? ? ? ?}else if(endContentOffsetX > willEndContentOffsetX&&
? ? ? ? ? ? ? willEndContentOffsetX > startContentOffsetX) {
? ? ? ? ? ? ? NSLog(@"畫面從左往右移動(dòng)浆竭,后一頁");
? ? }
}
tip 33 :? 判斷是否插入SiM卡
引入:CoreTelephony.framework
extern NSString*constkCTSMSMessageReceivedNotification;
extern NSString*constkCTSMSMessageReplaceReceivedNotification;
extern NSString*constkCTSIMSupportSIMStatusNotInserted;
extern NSString*constkCTSIMSupportSIMStatusReady;
id CTTelephonyCenterGetDefault(void);
void CTTelephonyCenterAddObserver(id,id,CFNotificationCallback,NSString*,void*,int);
void CTTelephonyCenterRemoveObserver(id,id,NSString*,void*);
int CTSMSMessageGetUnreadCount(void);
int CTSMSMessageGetRecordIdentifier(void* msg);
NSString* CTSIMSupportGetSIMStatus();
NSString* CTSIMSupportCopyMobileSubscriberIdentity();
id CTSMSMessageCreate(void* unknow/*always 0*/,NSString* number,NSString* text);
void* CTSMSMessageCreateReply(void* unknow/*always 0*/,void* forwardTo,NSString* text);
void* CTSMSMessageSend(idserver,idmsg);
NSString*CTSMSMessageCopyAddress(void*,void*);
NSString*CTSMSMessageCopyText(void*,void*);
NSLog(@"BOOL:%d", [CTSIMSupportGetSIMStatus()isEqualToString:kCTSIMSupportSIMStatusNotInserted] );
tip 34 :? 獲取鏈接的Wifi
#import <SystemConfiguration/CaptiveNetwork.h>
- (id)fetchSSIDInfo {
? ? ? ? ? NSArray*ifs = (__bridge_transfer id)CNCopySupportedInterfaces();
? ? ? ? ? NSLog(@"Supported interfaces: %@", ifs);
? ? ? ? ?id info =nil;
? ? ? ? ?for (NSString*ifnam in ifs) {
? ? ? ? ? ? ? ?info = (__bridge_transfer id)CNCopyCurrentNetworkInfo((__bridge CFStringRef)ifnam);
? ? ? ? ? ? ? ?NSLog(@"%@ => %@", ifnam, info);
? ? ? ? ? ? ? if(info && [info count]) {break; }
? ? ? ?}
? ? ? ? ?return info;
}
tip 35 :? 計(jì)算文字寬度、高度
- (CGSize)currentSize{
? ? ? CGFloatversion = [[UIDevice currentDevice].systemVersionfloatValue];
? ? //計(jì)算size? 7之后有新的方法
? ? ?CGSize size;
? ? if(version>=7.0) {
//得到一個(gè)設(shè)置字體屬性的字典
? ? NSDictionary*dic = [NSDictionary dictionaryWithObjectsAndKeys: ? ? ?[UIFontsystemFontOfSize:15],NSFontAttributeName,nil];
//optinos前兩個(gè)參數(shù)是匹配換行方式去計(jì)算惨寿,最后一個(gè)參數(shù)是匹配字體去計(jì)算
//attributes傳入使用的字體
//boundingRectWithSize計(jì)算的范圍
//_tweetBody是string
? ?size = [_tweetBody boundingRectWithSize:CGSizeMake(215,999)options:NSStringDrawingTruncatesLastVisibleLine|NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading attributes:diccontext:nil].size;
? ? }else{
//ios7以前
//根據(jù)字號(hào)和限定范圍還有換行方式計(jì)算字符串的size
//label中的font和linebreak要與此一致
//CGSizeMake(215,999)橫向最大計(jì)算到215縱向max 999
? ? size = [_tweetBodysizeWithFont:[UIFont systemFontOfSize:15]constrainedToSize:CGSizeMake(215,999) lineBreakMode:NSLineBreakByCharWrapping];
? ?}
? ? return size;
}
tip 36 :? TableView? UITableViewStylePlain狀態(tài)去掉省略多余的cell
_tableView= [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
_tableView.delegate=self;
_tableView.dataSource=self;
_tableView.tableFooterView= [UIView new]; ?// 關(guān)鍵的一行代碼
tip 37 : block? 類型聲明為strong 還是 copy ?
block聲明為strong 和copy什么區(qū)別
block變量申明為strong或者copy 在ARC 的情況下 是等效的
但蘋果推薦的最佳實(shí)踐是 使用copy作為block的權(quán)限控制符
因?yàn)?copy能讓開發(fā)者更明確地知道 block內(nèi)存操作的隱式行為
及copy 到heap上
ARC下面 strong修飾的block 會(huì)自動(dòng)進(jìn)行這一過程
MRC下面 使用copy是必須的
tip 38 :? 坐標(biāo)轉(zhuǎn)換
如果我的tableView的每個(gè)cell都有輸入框邦泄,那我怎么樣在輸入的時(shí)候?qū)?yīng)的輸入框移到合適的位置?
每個(gè)cell可以拿到在當(dāng)前table的位置然后轉(zhuǎn)換到屏幕上
然后自己算應(yīng)該偏移多少
self是一個(gè)view? 一個(gè)是把一個(gè)坐標(biāo)從自己的換到其他的View上
一個(gè)是把其他的坐標(biāo)換到自己上??如果self你當(dāng)做tableView裂垦,然后后面的uiview你用vc.view
就能相互轉(zhuǎn)了
tip 39 : 跳轉(zhuǎn)至指定QQ號(hào)碼
判斷是否安裝了QQ:
if([[UIApplication shareApplication] ?canOpenURL:[NSURL:URLWithString:@“mqq://“]]){
? ? ? ? ? NSLog(@“had installed");
} else {
? ? ? ? ? NSLog(@“no installed");
}
UIWebView*webView = [[UIWebView alloc] initWithFrame:CGRectZero];
NSURL*url?=?[NSURLURLWithString:@"mqq://im/chat?chat_type=wpa&uin=501863587&version=1&src_type=web"];
NSURLRequest*request?=?[NSURLRequest requestWithURL:url];
webView.delegate=self;
[webView loadRequest:request];
[self.view addSubview:webView];
tip 40 :? 企業(yè)版app 與 appStore版app之間的問題
問題一 : 一臺(tái)手機(jī)能否裝兩個(gè)名字一樣的應(yīng)用呢.
回答 : 能否裝兩個(gè)一樣的應(yīng)用不是取決于應(yīng)用的名字顺囊,而是取決于boundid,appId(這個(gè)本人還沒考究蕉拢。特碳。。)是否一致晕换。
但是蘋果應(yīng)用商店是不允許有兩個(gè)名字一樣的應(yīng)用程序的午乓,那我們干嘛要糾結(jié)于名字一樣的問題呢?
因?yàn)槿绻居幸粋€(gè)企業(yè)賬號(hào)和一個(gè)發(fā)布賬號(hào)闸准,企業(yè)賬號(hào)希望發(fā)布一個(gè)到官網(wǎng)供用戶下載益愈,而發(fā)布賬號(hào)希望發(fā)布到AppStore,而且名字一樣恕汇。
結(jié)論是:兩個(gè)應(yīng)用同名行不行腕唧?行或辖,只要你的企業(yè)賬號(hào)發(fā)布的應(yīng)用的boundid跟AppStore上的應(yīng)用的app的boundid不一致瘾英,名字可以一致。
而且蘋果不會(huì)管你的企業(yè)賬號(hào)發(fā)布的應(yīng)用程序颂暇,你愛怎么玩就怎么玩缺谴,如果你不希望一臺(tái)手機(jī)裝兩個(gè)名字一樣的應(yīng)用,那么開發(fā)者 ? ? ? ? ? ? ?只要將兩個(gè)應(yīng)用的boundid設(shè)置成一樣就可以了耳鸯。
注意:AppStore上不能有同名的應(yīng)用程序湿蛔,這個(gè)是受商標(biāo)保護(hù)法保護(hù)的。但是企業(yè)賬號(hào)就可以任意起名字跟設(shè)置boundid县爬。但是嘛阳啥,你懂的。财喳。察迟。
tip 41 : 打印 NSHomeDirectory為空
情況:打印獲取 NSHomeDirectory為空斩狱,打印有值,獲取到為nil扎瓶。所踊。
如果版本是release,就會(huì)出現(xiàn)上面的情況
解決的辦法 : 設(shè)置成 debug
安全的做法是:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
NSString *basePath = ([paths count] > 0) ? [paths objectAtIndex:0] : NSTemporaryDirectory();
tip 42 :? app跳轉(zhuǎn)到safari
NSURL* url = [NSURL URLWithString:urlStr];
[[UIApplication sharedApplication] openURL:url];
tip 43 : ?彈出鍵盤 & 收鍵盤
//監(jiān)聽鍵盤
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyBoardShow:)name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyBoardHide:)name:UIKeyboardWillHideNotification object:nil];
#pragma mark彈出鍵盤
-(void)keyBoardShow:(NSNotification*)notification
{
//notification.userInfo獲得用戶的所有信息概荷,userInfo是一個(gè)字典秕岛,根據(jù)key值 ? ? 為UIKeyboardFrameEndUserInfoKey拿到鍵盤的frame的“字符串”,將這個(gè)字符串轉(zhuǎn)成Rect
? ? ? ? int y = [[notification.userInfoobjectForKey:UIKeyboardFrameBeginUserInfoKey]CGRectValue].size.height;
}
#pragma mark收鍵盤
-(void)keyBoardHide:(NSNotification*)notification
{
}
最強(qiáng)的收鍵盤方法 :
[[UIApplicationsharedApplication]sendAction:@selector(resignFirstResponder)to:nilfrom:nilforEvent:nil];
其他的鍵盤監(jiān)聽 :
[[NSNotificationCenterdefaultCenter]addObserver:selfselector:@selector(keyboardWillChangeFrame:)name:UIKeyboardDidChangeFrameNotificationobject:nil];
tip 44 : ?審核加急處理
鏈接:https://developer.apple.com/appstore/contact/appreviewteam/index.html
備注:到上面的連接填寫相關(guān)桂東误证,申請加急的理由:上線的App中有Bug
tip 45 : ?iTunesConnect 更新版本接受協(xié)議步驟
tip 46 :? No architectures to compile for (ONLY_ACTIVE_ARCH=YES, active arch=x86_64, VALID_ARCHS=i386).
解決的辦法是 :
步驟1 : ?
步驟2 :
tip 47 :? Version 號(hào) 跟Build ?號(hào)的區(qū)別
version 是給用戶看的继薛,比如1.0? 2.0
Build 是給開發(fā)者還有就是蘋果 iTunesconnect看的
具體情景:
今天發(fā)布一個(gè)版本叫 2.0 所以 version 2.0
于是我要archive?-> validate -> submit
發(fā)布完成了!
正當(dāng)我們其樂融融的的準(zhǔn)備慶祝的時(shí)候愈捅,屌絲的產(chǎn)品進(jìn)來大吼一聲惋增,肅靜,吵什么吵改鲫,我看那個(gè)搜附近的人頁面太爛了U┟蟆!O窦稽亏!
一萬個(gè)草泥馬在天上飛啊。缕题。截歉。
沒事,蛋定烟零,蛋定瘪松,改改改。锨阿。宵睦。
改完之后,發(fā)現(xiàn)validate不成功墅诡。提示:已經(jīng)有一個(gè)2.0的版本了壳嚎,怎么破?末早?烟馅??產(chǎn)品經(jīng)理堅(jiān)持要用version 2.0這個(gè)數(shù)字然磷,但是如果不改成version2.1之類的好像一直都傳不上去爸3谩!W怂选寡润!靈光一閃缺脉,Build 號(hào)是干嘛的?經(jīng)過一般查證悦穿,Build是給我們開發(fā)者和itunesconnect看的攻礼,改一下Build不就行了嗎,改改改栗柒,重新validate發(fā)現(xiàn)可行礁扮,歐耶,submit , 重新選擇版本瞬沦,搞定L痢!逛钻!繼續(xù)慶祝
tip 48 :?Xcode 6中對于圖片的要求規(guī)格:
1僚焦、AppIcon
(1)spotlight iOS 5-6 29*29
setting iOS 5-8 29*29 (1*2*3 三種尺寸)
(2)spotlight iOS 7-8 40*40 (2*3 兩種尺寸)
(3)iPhone App iOS 5-6 57*57 (1*2兩種尺寸)
(4)iPhone App iOS 7-8 60*60 (2*3兩種尺寸)
2、啟動(dòng)圖片
Default.png(320*480)
Default@2x.png(640*960)
Default-568h@2x.png(640*1136)
Default-667h@2x.png(750*1334) 4.7寸
Default-736h@3x.png(1242*2208)5.5寸
tip 49 :? 清除簽名文件 刪除簽名文件 清理Profile文件
Xcode - Preferences - Account - View Details,這個(gè)時(shí)候左下角有個(gè)刷新圖標(biāo)曙痘,點(diǎn)擊一下就可以了
tip 50 : ?應(yīng)用內(nèi)跳轉(zhuǎn)到系統(tǒng)設(shè)置頁面 (轉(zhuǎn))
http://code4app.com/ios/DBPrivacyHelper/548e7550933bf031268b4d82
tip 51 : ?使用lipo命令合并對應(yīng)版本 靜態(tài)庫文件
備注:以百度地圖SDK為栗子
真機(jī)版本的文件路徑:?/Users/han-zi/Desktop/Release-iphoneos/libbaidumapapi.a
模擬器版本的文件路徑:/Users/han-zi/Desktop/Release-iphonesimulator/libbaidumapapi.a
輸出文件路徑: /Users/han-zi/Desktop/a/libbaidumapapi.a
tip 52 : 應(yīng)用在AppStore的地址
webpageUrl=@"http://itunes.apple.com/us/app/id+你的應(yīng)用id";
tip 53 :? 顏色值轉(zhuǎn)RGB
- (void)setBgRGB:(long)rub{
? ? ? ? ? ?red = ((float)((rgb & 0xFF0000) >> 16))/255.0;
? ? ? ? ? ?green = ((float)((rgb & 0xFF00) >> 8))/255.0;
? ? ? ? ? blue = ((float)(rgb & 0xFF))/255.0;
}
tip 54 : ?App 上線簡介
心得體會(huì):
1.準(zhǔn)備一個(gè)APP ID(這個(gè)可以永遠(yuǎn)用)
2.創(chuàng)建證書
a.創(chuàng)建證書的過程要上傳機(jī)器標(biāo)示符(鑰匙串——>證書助理——>從證書頒發(fā)機(jī)構(gòu)請求證書))
b.要綁定APP ID
c.填寫bundleID
d.下載證書
3.生成簽名文件——>綁定Bundle ID ——>生成簽名文件——>下載簽名文件
tip 55 : UIImage加載方式怎么選芳悲?
方式一: imageName:有緩存的方式,如果一張圖片會(huì)被重復(fù)用到边坤,那么請用這種方式
方式二:contentOfFile:無緩存的方式名扛,加載大的圖片文件,特別注意茧痒,jpg圖片只能以這種方式加載
tip 56 :? ARC兼容MRC肮韧,MRC兼容ARC 設(shè)置關(guān)鍵字
ARC兼容MRC : -fno-objc-arc
MRC兼容ARC: -fobjc-arc
tip 57 :? 消息推送機(jī)制理解
1.應(yīng)用程序第一次起來的時(shí)候詢問是否允許消息推送,允許的時(shí)候才去注冊旺订,
向蘋果APNS服務(wù)器注冊是哪個(gè){應(yīng)用程序弄企,設(shè)備號(hào)}
2.注冊成功蘋果APNS服務(wù)器返回一個(gè)DeviceToken,程序員要保存這個(gè){DeviceToken}
3.注冊失敗 区拳。拘领。。劳闹。
4.注冊成功院究,將DeviceToken發(fā)給服務(wù)器{可以是自己的服務(wù)器,可以是極光服務(wù)器}本涕,服務(wù)器保存這一大堆的DeviceToken
5.服務(wù)器要推送消息{可以是極光服務(wù)器}將這個(gè)消息發(fā)給蘋果APNS服務(wù)器,APNS服務(wù)器根據(jù){一大堆的DevicToken}向應(yīng)用程序推送消息
tip 58 : ?FMDB 事務(wù)操作步驟
@try{
啟動(dòng)事務(wù)伙窃,執(zhí)行數(shù)據(jù)庫操作
[_dataBase beginTransaction];//手動(dòng)開啟一個(gè)事務(wù)
}@Catch{
出現(xiàn)問題菩颖,數(shù)據(jù)庫回滾
[_dataBase rollback];//回滾,回到最初的狀態(tài)
}@finally{
數(shù)據(jù)庫提交操作
[_dataBase commit];//提交事務(wù)为障,讓批量操作生效
}
備注:FMDB 使用進(jìn)階包括兩個(gè)內(nèi)容晦闰,一個(gè)是事務(wù)放祟,一個(gè)是線程安全,詳細(xì)內(nèi)容請看FMDB官方文檔呻右。
事務(wù)解決的問題: 如果要對數(shù)據(jù)庫進(jìn)行 多條數(shù)據(jù)的寫操作跪妥,應(yīng)開啟事務(wù),而不要只使用for循環(huán)直接寫入声滥,否則會(huì)比較耗時(shí)
線程安全解決的問題: 如果對同一資源進(jìn)行操作眉撵,F(xiàn)MDB不是線程安全的,使用FMDataBaseQueue這個(gè)類可以做到線程安全落塑。
tip 59 : UITableView重用機(jī)制的理解
UITableView自身有一套重用的機(jī)制纽疟,根據(jù)UITaleVIew 的frame的大小和cell.frame大小來計(jì)算個(gè)數(shù),實(shí)際會(huì)創(chuàng)建多一個(gè)cell憾赁,創(chuàng)建的這些cell都放在一個(gè)數(shù)組(隊(duì)列的數(shù)據(jù)結(jié)構(gòu))里面污朽,視圖出現(xiàn)時(shí)根據(jù)計(jì)算的結(jié)果將cell拿出來放在UITableView上面,剩下的那個(gè)cell則作為緩沖cell龙考,比如向上拖動(dòng)的時(shí)候蟆肆,cell[0]會(huì)放回?cái)?shù)組最下面,將那個(gè)上次沒有使用的cell拿出來晦款,放在TableView下面颓芭。利用這種機(jī)制來達(dá)到重用的目的。
對于拖到到看不見的位置的cell柬赐,我們可以對他清除緩存(緩存就是cell.contentView上面的子view)亡问,那怎么清除呢?方法很簡單
-(UITableViewCell *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
? ? ? ? ? ? ?if(cell ! == nil)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? NSArray *arr =[ [NSArray alloc] initWithArray :cell.contentView.subviews];
? ? ? ? ? ? ? ? ? ?for (UIView *subView in arr){
? ? ? ? ? ? ? ? ? [subView removeFromSuperView];
? ? ? ? ? }
}
tip 60 :? UITableView Cell 清除緩存 說白了就是將將要出現(xiàn)的cell的contentView上面的子視圖清除掉或銷毀
tableView表格中的cell有重用機(jī)制肛宋,這是一個(gè)很好的東西州藕,可以避免開辟很多的空間內(nèi)存。但是有時(shí)候我們不想讓它重用cell酝陈,床玻,可以用以下的代碼解決。
將這個(gè)代碼放在:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{?
? ? ? ? ? ?// 這個(gè)函數(shù)中執(zhí)行就好了沉帮。
? ? ? ? ? ?//清楚cell的緩存
? ? ? ? ? ?NSArray *subviews = [[NSArray alloc] initWithArray:cell.contentView.subviews];
? ? ? ? ? ?for(UIView *subview in subviews) {
? ? ? ? ? ?[subview removeFromSuperview];
}
tip 61 :? 改變tabBarItem字體顏色
self.tabBar.tintColor= [UIColor colorWithHexString:BLUE_GREEN_COLOR];
UITabBarController*tabBarController = (UITabBarController*)self;
UITabBar*tabBar = tabBarController.tabBar;
UITabBarItem*trainEnquiryItem? = [tabBar.itemsobjectAtIndex:0];
[trainEnquiryItem setTitle:@"查詢"];
[trainEnquiryItemsetImage:[UIImageimageNamed:@"tet"]];
[trainEnquiryItemsetSelectedImage:[UIImageimageNamed:@"tet_hover"]];
改變UITabBarItem 字體顏色
[[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor],UITextAttributeTextColor,nil] forState:UIControlStateNormal];
[[UITabBarItem appearance]setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor colorWithHexString:"#00C8D3"],UITextAttributeTextColor,nil] forState:UIControlStateSelected];
tip 62 : ?UITextFiled 設(shè)置PlaceHolder字體顏色
#pragma mark設(shè)置Placeholder顏色
UIColor*color = [UIColorwhiteColor];
_userNameTextField.attributedPlaceholder= [[NSAttributedStringalloc]initWithString:@"用戶名/郵箱"attributes:@{NSForegroundColorAttributeName: color}];
[tempUserNameImageViewaddSubview:_userNameTextField];
tip 63 : ?應(yīng)用主題設(shè)置心得以及思路
THEME是主題名稱
同理锈死,所有涉及到界面的地方都要監(jiān)聽THEME通知,
IOS有關(guān)主題的問題? ThemeManager 類
1.創(chuàng)建路徑:初始化時(shí)先從指定的plist文件中讀取主題文件
2.根據(jù)路徑初始化有關(guān)主題的數(shù)組
3.如果這個(gè)數(shù)組為空穆壕,初始化為0個(gè)對象
4.接口 :
-(BOOL)downLoad:(NSDictionary *)dic Block:(void? (^) (BOOL))a
{
//1.保存block
//2.從字典中獲得主題名稱
//3.數(shù)組中保存這個(gè)主題文件: 根據(jù)名字判斷主題是否已經(jīng)存在
[self.dataArray containsObject:self.tempTheme];
//4.1存在:NSUserDefault保存——>通知中心發(fā)送通知post——>結(jié)束返回
//4.2? 根據(jù)url發(fā)起網(wǎng)絡(luò)請求——>
進(jìn)行下載——>
下載完成保存文件——>
}
-(void)saveData:(NSData *)data
{
保存到指定文件——>
解壓縮文件——>
用NSUserDefault記錄主題名待牵,啟動(dòng)的時(shí)候方便讀取——>
//4.3主題持久化工作
將主題名字保存到數(shù)組中,將整個(gè)數(shù)組寫到初始化時(shí)的plist文件目錄中 ,(里面包含所有的主題名稱) writeToFile
//4.4保存完發(fā)送主題廣播 post
//4.5發(fā)送廣播喇勋,調(diào)用回調(diào)函數(shù)
//4.6在MainTabBarController里面配置界面缨该,相當(dāng)于設(shè)置主題,不同主題川背,里面的圖片的名字是不一樣的
}
在某個(gè)類中使用新的主題文件 比如:MainViewController:
-(void)dealloc{
[ [NSNotificationCenter defaultCenter] removeObserver:self name:THEME object :nil];
}
-(void)viewDidLoad
{
//順序不可以顛倒
[self createTabBarItem];
//接收通知后一定要在第一次讀取默認(rèn)主題創(chuàng)建好之后再接收 createTabBarItem是布局界面的方法
[ [NSNotification defaultCenter]? addObserver:self? selector:@selector(createTabBarItem) name:THEME object:nil];
}
-(void)createTabBarItem
{
//設(shè)置界面主題圖片
}
tip 64 :? 設(shè)置UITabBarItem文字屬性
//設(shè)置文字顏色
if(iOS7) {
? ? ? ? ?[[UITabBarItem appearance]setTitleTextAttributes:@{NSForegroundColorAttributeName: ? ? ? ? ? ? ? ? ? ?[UIColorwhiteColor]}forState:UIControlStateSelected];
}else{
? ? ? ?[[UITabBarItem appearance]setTitleTextAttributes:@{UITextAttributeTextColor: [UIColorwhiteColor]}forState:UIControlStateSelected];
}
tip 65 : 設(shè)置UITabBarItem背景圖片
if(iOS7) {
? ? ? item = [iteminitWithTitle:title[i]
? ? ?image:[unSelectImageimageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]
? ? selectedImage:[selectImageimageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
}else{
? ? ?itemsetFinishedSelectedImage:selectImagewithFinishedUnselectedImage:unSelectImage];
? ? ?item.title= title[i];
}
tip 66 : ?一個(gè)View旋轉(zhuǎn)一定角度
//M_PI == 3.14 == 180
[btn setTransform:CGAffineTransformMakeRotation(M_PI/7.2)];//25
tip 67 : 一些crash崩潰原因
1贰拿、對象里面沒有某個(gè)方法
2蛤袒、自己建的類沒有NSCopying協(xié)議,就去copy
3膨更、對某類的對象進(jìn)行歸檔接檔妙真,沒有實(shí)現(xiàn)NSCoding協(xié)議
4、下標(biāo)越界
5荚守、導(dǎo)航視圖控制器出棧時(shí)珍德,某個(gè)vc不在
6、數(shù)據(jù)為空健蕊,沒有初始化
tip 68 : id類型不能用點(diǎn)語法
tip 69 :? 設(shè)置睡眠 & 產(chǎn)生真正的隨機(jī)數(shù)
sleep(1.f); ?// 睡眠一秒
arc4random()%10; // 10以內(nèi)的隨機(jī)數(shù)
tip 70 :?參數(shù)要遵循某種協(xié)議的寫法
void?play(id ins) // look at here
{
? ? ?if?([ins?respondsToSelector:@selector(playMusic)]) {
? ? ? ? ? ? [ins?playMusic];
? ? ?}
}
tip 71 : ?NSString的一些特殊情況
//__autoreleasing?對象設(shè)置為這樣菱阵,要等到離自己最近的釋放池銷毀時(shí)才release
//__unsafe__unretained不安全不釋放,為了兼容過去而存在缩功,跟__weak很像,但是這個(gè)對象被銷毀后還在晴及,不像__weak那樣設(shè)置為nil
//__weak?一創(chuàng)建完,要是沒有引用嫡锌,馬上釋放虑稼,將對象置nil
//
__weak?NSMutableString?*str = [NSMutableString?stringWithFormat:@"%@",@"xiaobai"];
//__weak?的話但是是alloc的對象,要交給autorelease管理
//arc下,不要release?和?autorelease因?yàn)?/p>
tip 72 : 判斷類势木,成員蛛倦,調(diào)用方法
[obj isMemberOfClass:[runTime class]] //判斷是不是一個(gè)一個(gè)類的成員
[obj isKindOfClass:[NSObject class]]?//是不是從屬一個(gè)類,包括父類
[obj?conformsToProtocol:@protocol(NSCoding)]//是不是支持這一個(gè)協(xié)議
[obj?performSelector:@selector(showA:)?withObject:[NSNumber?numberWithInt:8]]//給方法發(fā)送消息
tip 73 : ?文件操作注意事項(xiàng)
//NSFileHandle * fh = [NSFileHandle fileHandleForReadingAtPath:@"/Users/qianfeng/Desktop/C考試準(zhǔn)備"];
//[fh seekToFileOffset:2];//定位到某處開始執(zhí)行操作,顯示的seek會(huì)更新文件指針
//NSData * data = [fh availableData];
//NSData *data = [fh readDataOfLength:2];
寫文件的注意事項(xiàng)
voidtestArchiver()//“支持nscopy的可以寫到文件”
{
NSString* str =@"123445788";
NSArray* array = [[NSArray alloc]initWithObjects:@"nihao",nil];
[strwriteToFile:@"/Users/qianfeng/Desktop/筆記本使用注意事項(xiàng)2.text"atomically:YES encoding:NSUTF8StringEncodingerror:nil];
[arraywriteToFile:@"djhfdj"atomically:YES];//讀寫保護(hù)
}
voidtest3()//NSCode是能將OC類型寫到文件的
{
Myfiler* mf = [[Myfileralloc]init];
NSArray* array = [NSArray arrayWithObject:mf];
[arraywriteToFile:@"djhfdjf"atomically:YES];//失敗啦桌,因?yàn)槠胀怣yfiler不支持nscopy協(xié)議
}
由于篇幅關(guān)系溯壶,未完待續(xù)!