開篇
這篇文章是我工作幾個月以來出現的問題的解決方案 典阵, 寫出來方便自己以后過來查看
1.工具類(Xcode)方面的問題
-
一鍵生成Appicon 的網站以及工具APP
1 http://icon.wuruihong.com/#/home
2 http://ydimage.yidianhulian.com/
3 https://itunes.apple.com/cn/app/id476533227?mt=12
-
關于狀態(tài)欄的問題
- 讓狀態(tài)欄變成白色
self.navigationController.navigationBar.barStyle = UIBarStyleBlackOpaque;
2.隱藏狀態(tài)欄
- 讓狀態(tài)欄變成白色
-(BOOL)prefersStatusBarHidden {
return YES;
}
-
Mac 終端的小技巧
1.mac默認是看不到隱藏文件的绢记,例如git之類的文件夾是看不到的,先看到的話打開終端
打開終端,輸入:
defaults write com.apple.finder AppleShowAllFiles -bool true 此命令顯示隱藏文件
defaults write com.apple.finder AppleShowAllFiles -bool false 此命令關閉顯示隱藏文件
命令運行之后需要重新加載Finder:快捷鍵option+command+esc,選中Finder,重新啟動即可
2.利用uuidgen 這個命令可以生成隨機的UUID
3.統(tǒng)計項目總代碼行數
打開終端
①cd進入工程文件夾下
②執(zhí)行命令find . "(" -name ".m" -or -name ".mm" -or -name ".cpp" -or -name ".h" -or -name "*.rss" ")" -print | xargs wc -l
2.tableView方面的問題
- 獲取tableView的cell
在這個例子中,當改變picker值的時候蕉鸳,Cell中的值也跟著改變。以前就一直很糾結怎么獲取選中的Cell忍法,看過這個例子后潮尝,真是豁然開朗呀无虚!
這個例子里用到了一個方法:indexPathForSelectedRow,用這個方法就能獲取選擇的cell了--衍锚!以前怎么沒發(fā)現...
關鍵代碼:
- (IBAction)dateAction:(id)sender{
//這樣就把選擇的cell找出來了友题?真經典orz
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
cell.detailTextLabel.text= [self.dateFormatter stringFromDate:self.pickerView.date];
[self.tableView deselectRowAtIndexPath:indexPathanimated:YES];//注意!這句話可不能再放在didselected...的那個方法里
}
補充問題:以上方法只有在點擊cell時才能確定cell的index戴质,而如果點擊了cell上的button度宦,用上面的方法還是沒辦法解決。
解決辦法:由按鈕獲得它SuperView,即你自己定義的cell,知道這個cell了后在得到它的行數告匠。
tableView分割線調整 去除底部多余的線
//分割線調整
_tableView.separatorInset= UIEdgeInsetsMake(0, 10, 0, 10);
//去除多余的線 原理創(chuàng)建一個空的View 作為tableView 的footView
UIView *footView = [UIView new];
_tableView.tableFooterView = footView;
刪除分割線 讓它不顯示
tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
- 讓tableView cell 不能選中
self.tableView.allowsSelection = NO;
- 讓tableView 透明
cell.backgroundColor = [UIColor clearColor];
_tableView.backgroundColor = [UIColor clearColor]; ```
* 一進來頁面讓tableView默認選中第幾行
[self.tableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:row inSection:0] animated:YES scrollPosition:UITableViewScrollPositionMiddle];
* tableView 自定義重寫
//重寫父類方法
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
if (self=[super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
[self initUI];
}
return self;
}
3.其他小技巧
---
* 注釋
接下來要分享的是添加注釋文檔的快捷鍵: ? command + ? option + /
這個快捷鍵的功能跟 VVDocumenter 一樣戈抄,可以給函數名,變量名等生成好看的注釋文檔
http://www.reibang.com/p/dad949fea031
* 獲取當前時間
- (NSString *)loadCurrentDate
{
NSDateFormatter *dateFormatter =[[NSDateFormatter alloc] init];
// 設置日期格式
[dateFormatter setDateFormat:@"YYYY-MM-dd hh:mm:ss"];
NSString *dateString = [dateFormatter stringFromDate:[NSDate date]];
// DDLogDebug(@"currentDate------------%@", [NSDate date]);
return dateString;
}
* 隨機數 相關
> arc4random_uniform(x)
產生[0,x)的隨機數后专。
>獲得指定范圍的隨機數
(int)getRandomNumber:(int)from to:(int)to
{
return (int)(from + (arc4random() % (to - from + 1)));
}
* xcode 支持的iOS系統(tǒng)包文件夾路徑
> ios10包放在: 應用程序–顯示包內容–Developer–Platforms–iPhoneOS.platform–DeviceSupport里
ios10包地址: http://pan.baidu.com/s/1kUQnKAr 49tn
* 顏色轉換為背景圖片
// 顏色轉換為背景圖片
- (UIImage *)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;
}
* AFNetworking 請求頭的設置
delete 請求頭設置
- (instancetype)hrManager
{
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
manager.responseSerializer = [AFNJSONResponseSerializerWithData serializer];
[manager.requestSerializer setValue:[self generateUserAgent] forHTTPHeaderField:@"User-Agent"];
NSString *token = [HRServicesManager sharedManager].token;
if (token) [manager.requestSerializer setValue:token forHTTPHeaderField:TOKEN_HEADER_NAME];
manager.responseSerializer.acceptableContentTypes = [manager.responseSerializer.acceptableContentTypes setByAddingObject:@"text/plain"];
return manager;
}
post請求頭設置
- (instancetype)hrPostManager
{
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
manager.responseSerializer = [AFHTTPResponseSerializer serializer];
manager.responseSerializer = [AFNJSONResponseSerializerWithData serializer];
[manager.requestSerializer setValue:[self generateUserAgent] forHTTPHeaderField:@"User-Agent"];
NSString *token = [HRServicesManager sharedManager].token;
if (token) [manager.requestSerializer setValue:token forHTTPHeaderField:TOKEN_HEADER_NAME];
manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript",@"text/html", @"text/plain", nil];
[manager.requestSerializer setValue:@"application/x-www-form-urlencoded;charset=UTF-8" forHTTPHeaderField:@"Content-Type"];
return manager;
}