iOS學(xué)習(xí)資料三

每天學(xué)習(xí)一點(diǎn)點(diǎn),休息一會會。

1、禁止手機(jī)睡眠

[UIApplication sharedApplication].idleTimerDisabled = YES;

2、隱藏某行cell

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

{

// 如果是你需要隱藏的那一行,返回高度為0

if(indexPath.row == YouWantToHideRow)

return 0;

return 44;

}

// 然后再你需要隱藏cell的時候調(diào)用

[self.tableView beginUpdates];

[self.tableView endUpdates];

3、禁用button高亮

button.adjustsImageWhenHighlighted = NO;

或者在創(chuàng)建的時候

UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];

4、tableview遇到這種報錯failed to obtain a cell from its dataSource

是因?yàn)槟愕腸ell被調(diào)用的早了。先循環(huán)使用了cell,后又創(chuàng)建cell。順序錯了

可能原因:1、xib的cell沒有注冊 2、內(nèi)存中已經(jīng)有這個cell的緩存了(也就是說通過你的cellId找到的cell并不是你想要的類型),這時候需要改下cell的標(biāo)識

5、cocoa pods報這個錯誤:unable to access ‘https://github.com/facebook/pop.git/': Operation timed out after 0 milliseconds with 0 out of 0 bytes received

解決辦法:原因可能是網(wǎng)絡(luò)問題,網(wǎng)絡(luò)請求超時了,只需要重試就行了

6、cocoa pods 出現(xiàn)ERROR: While executing gem ... (Errno::EPERM)

解決辦法:

https://segmentfault.com/q/1010000002926243

7、動畫切換window的根控制器

// options是動畫選項(xiàng)

[UIView transitionWithView:[UIApplication sharedApplication].keyWindow duration:0.5f options:UIViewAnimationOptionTransitionCrossDissolve animations:^{

BOOL oldState = [UIView areAnimationsEnabled];

[UIView setAnimationsEnabled:NO];

[UIApplication sharedApplication].keyWindow.rootViewController = [RootViewController new];

[UIView setAnimationsEnabled:oldState];

} completion:^(BOOL finished) {

}];

8、去除數(shù)組中重復(fù)的對象

NSArray *newArr = [oldArr valueForKeyPath:@“@distinctUnionOfObjects.self"];

9、編譯的時候遇到 no such file or directory: /users/apple/XXX

是因?yàn)榫幾g的時候,在此路徑下找不到這個文件,解決這個問題,首先是是要檢查缺少的文件是不是在工程中,如果不在工程中,需要從本地拖進(jìn)去,如果發(fā)現(xiàn)已經(jīng)存在工程中了,或者拖進(jìn)去還是報錯,這時候需要去build phases中搜索這個文件,這時候很可能會搜出現(xiàn)兩個相同的文件,這時候,有一個路徑是正確的,刪除另外一個即可。如果刪除了還是不行,需要把兩個都刪掉,然后重新往工程里拖進(jìn)這個文件即可


10、iOS8系統(tǒng)中,tableView最好實(shí)現(xiàn)下-tableView: heightForRowAtIndexPath:這個代理方法,要不然在iOS8中可能就會出現(xiàn)顯示不全或者無法響應(yīng)事件的問題

11、iOS8中實(shí)現(xiàn)側(cè)滑功能的時候這個方法必須實(shí)現(xiàn),要不然在iOS8中無法側(cè)滑

// 必須寫的方法,和editActionsForRowAtIndexPath配對使用,里面什么不寫也行

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {

}

12、三個通知

NSSystemTimeZoneDidChangeNotification監(jiān)聽修改時間界面的兩個按鈕狀態(tài)變化

UIApplicationSignificantTimeChangeNotification 監(jiān)聽用戶改變時間 (只要點(diǎn)擊自動設(shè)置按鈕就會調(diào)用) NSSystemClockDidChangeNotification 監(jiān)聽用戶修改時間(時間不同才會調(diào)用)

13、SDWebImage本地緩存有時候會害人。如果之前緩存過一張圖片,即使下次服務(wù)器換了這張圖片,但是圖片url沒換,用sdwebimage下載下來的還是以前那張,所以遇到這種問題,不要先去懟服務(wù)器,清空下緩存再試就好了。

14、上線前注意:

1)、刪掉代碼中所有的測試代碼

2)、如果后臺有審核模式,提醒后臺開啟此模式

3)、主流程再跑一跑

4)、全局搜索waring,檢查所有標(biāo)記waring的地方

15、跳進(jìn)app權(quán)限設(shè)置

// 跳進(jìn)app設(shè)置

if (UIApplicationOpenSettingsURLString != NULL) {

NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];

[[UIApplication sharedApplication] openURL:url];

}

}

16、給一個view截圖

UIGraphicsBeginImageContextWithOptions(view.bounds.size, YES, 0.0);

[view.layer renderInContext:UIGraphicsGetCurrentContext()];

UIImage *img = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

17、開發(fā)中如果要動態(tài)修改tableView的tableHeaderView或者tableFooterView的高度,需要給tableView重新設(shè)置,而不是直接更改高度。正確的做法是重新設(shè)置一下tableView.tableFooterView = 更改過高度的view。為什么?其實(shí)在iOS8以上直接改高度是沒有問題的,在iOS8中出現(xiàn)了contentSize不準(zhǔn)確的問題,這是解決辦法。

18、注意對象為nil的時候,調(diào)用此對象分類的方法不會執(zhí)行

19、collectionView的內(nèi)容小于其寬高的時候是不能滾動的,設(shè)置可以滾動:

collectionView.alwaysBounceHorizontal = YES;

collectionView.alwaysBounceVertical = YES;

20、設(shè)置navigationBar上的title顏色和大小

[self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor youColor], NSFontAttributeName : [UIFont systemFontOfSize:15]}]

21、顏色轉(zhuǎn)圖片

+ (UIImage *)cl_imageWithColor:(UIColor *)color {

CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);

UIGraphicsBeginImageContext(rect.size);

CGContextRef context = UIGraphicsGetCurrentContext();

CGContextSetFillColorWithColor(context, [color CGColor]);

CGContextFillRect(context, rect);

UIImage *image = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

return image;

}

22、view設(shè)置圓角

#define ViewBorderRadius(View, Radius, Width, Color)\

\

[View.layer setCornerRadius:(Radius)];\

[View.layer setMasksToBounds:YES];\

[View.layer setBorderWidth:(Width)];\

[View.layer setBorderColor:[Color CGColor]] // view圓角

23、強(qiáng)/弱引用

#define WeakSelf(type)? __weak typeof(type) weak##type = type; // weak

#define StrongSelf(type)? __strong typeof(type) type = weak##type; // strong

24、由角度轉(zhuǎn)換弧度

#define DegreesToRadian(x) (M_PI * (x) / 180.0)

25.由弧度轉(zhuǎn)換角度

#define RadianToDegrees(radian) (radian*180.0)/(M_PI)

26、獲取圖片資源

#define GetImage(imageName) [UIImage imageNamed:[NSString stringWithFormat:@"%@",imageName]]

27、獲取temp

#define PathTemp NSTemporaryDirectory()

28、獲取沙盒 Document

#define PathDocument [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject]

29、獲取沙盒 Cache

#define PathCache [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) firstObject]

30、GCD代碼只執(zhí)行一次

#define kDISPATCH_ONCE_BLOCK(onceBlock) static dispatch_once_t onceToken; dispatch_once(&onceToken, onceBlock);

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容