標(biāo)簽(空格分隔): ios 開發(fā)中的那些坑
[TOC]
一、UITableview 使用技巧分享
分享人:@錢萌丹 @官洋 @老戴
tableViewCell 選中后背景View更換
// 使用selectedBackgroundView 可設(shè)置tableViewCell選中背景
// 注意使用該屬性的前提是,UITableViewCell的選中狀態(tài)類型不能設(shè)置為UITableViewCellSelectionStyleNone
tableViewCell.selectedBackgroundView
cell下方分割線如何縮進(jìn)
#pragma mark 設(shè)置tableview分割線到頂端
-(void)viewDidLayoutSubviews{
NSLog(@"%s",__FUNCTION__);
if ([self.mainTableView respondsToSelector:@selector(setSeparatorInset:)]) {
[self.mainTableView setSeparatorInset:UIEdgeInsetsMake(0,0,0,0)];
}
if ([self.mainTableView respondsToSelector:@selector(setLayoutMargins:)]) {
[self.mainTableView setLayoutMargins:UIEdgeInsetsMake(0,0,0,0)];
}
}
#pragma mark delegate
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
// 解決separator 線的縮進(jìn)
if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
[cell setSeparatorInset:UIEdgeInsetsZero];
}
// 解決tableViewCell 8像素縮進(jìn)
if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
[cell setLayoutMargins:UIEdgeInsetsZero];
}
}
二、UIScrollView 使用技巧分享
分享人 : @李銳
如果想設(shè)置UIScrollView的偏移量?
scrollView.contentInset = UIEdgeMake(64, 0, 0, 0);
三、UIImage 使用技巧分享
分享人: @王孜
UIImage 之前加載使用的file刪除,再次存儲UIImage到文件失敗
BUG出現(xiàn)描述
<Error>: ImageIO: CGImageReadCreateDataWithMappedFile 'open' failed '路徑'
error = 2 (No such file or directory)BUG出現(xiàn)操作還原
從本地沙盒讀取圖片,加載到UIimageViews上。
刪除沙盒里的圖片。
將UIImageView里的圖片保存到本地沙盒時,BUG出現(xiàn)。
- BUG出現(xiàn)原因解析與解決方法
原因:保存時,圖片已經(jīng)不存在了,所以保存失敗。
解決方案:從路徑讀取圖片后,先轉(zhuǎn)換成NSData,再生成一張新的image,之后保存就OK。
// 正確做法
UIImage *tempImage = [[UIImage alloc] initWithContentsOfFile:filePath];
NSData *tempData = UIImagePNGRepresentation(tempImage);
UIImage *newImage = [UIImage imageWithData:tempData];
// 錯誤做法
UIImage *newImage = [[UIImage alloc] initWithContentsOfFile:filePath];