1.NSlog??發(fā)布后不打印
#ifdef DEBUG//?如果有DEBUG這個宏就編譯下面一句代碼
#define DDLog(...) NSLog(__VA_ARGS__)
#else?//?如果沒有DEBUG這個宏就編譯下面一句代碼
#define DDLog(...)
#endif
2.三方庫及其他整理
用過的三方庫:
1.?AFNetworking ? HTTP 網絡請求庫
2.?SDWebImage 圖片緩存
3.?MBProgressHUD 加載中展示
4.MMDrawerController? 抽屜視圖(自己也可以模仿再重寫)?
5.?FMDB ?sqlite
6.MJRefresh? ? tableview 下拉刷新上拉加載
7.WebViewJavascriptBridge??實現OC與JS交互
8.SBJSON? ? json解析
9.MJExtension? ? ?模型轉換
10.SVPullToRefresh? ?scrollview 上加下拉刷新
11.?Masonry/SnapKit ? ? 自適應布局 (類安卓的相對布局,由于本人1年安卓2年iOS 用起來挺順手)
12.?AFPopupView ?實現炫酷的跳轉
13.?AwesomeMenu 實現炫酷工具欄效果
14.MJPhotoBrowser? ? 實現圖片瀏覽效果菱农,有個導致crash的bug顷帖,之后會更
15.ZXingObjC ? 二維碼
16.MKNetworkKit? 輕量級HTTP 網絡請求庫
17.jpush ? 推送
18.alipay ?支付寶支付
19.微信支付
20.友盟 ?分享赖舟、三方登陸啤誊、推送饺窿、數據記錄鲫咽、crash記錄
21.iCarousel? ?實現Coverflow效果姨伤。
22.SDCycleScrollView ?無限輪播器
沒有過的:
1.JSPatch js腳本更新線上代碼(應急用)
2.CocoaPod?? 三方庫的管理工具
3.更新Xcode后劫恒,三方插件不能用的解決方法
1.在終端中輸入 ?defaults read /Applications/Xcode.app/Contents/Info DVTPlugInCompatibilityUUID 會得到一串碼即本版本xocde的UUID贩幻,復制留用。
2.前往文件夾~/Library/Application Support/Developer/Shared/Xcode/Plug-ins/
這個插件目錄是所謂的插件目錄两嘴,找到相應的插件丛楚,右擊顯示報內容,打開里面的info.plist,找到DVTPlugInCompatibilityUUIDs 字段憔辫,將操作 1 中得到的UUID 添加到此處即可趣些。重啟xcode就可以使用了
4.獲取帶毫秒的NSDate
NSDateFormatter?*dateFormatter = [[NSDateFormatteralloc]?init];
[dateFormatter?setDateStyle:NSDateFormatterMediumStyle];
[dateFormatter?setTimeStyle:NSDateFormatterShortStyle];
//[dateFormatter setDateFormat:@"hh:mm:ss"]
[dateFormatter?setDateFormat:@"yyyy-MM-dd HH:mm:ss.SSS"];
NSLog(@"-------0Date%@", [dateFormatter?stringFromDate:[NSDate?date]]);
5.WebViewJavascriptBridge的使用
轉載2015-07-07 16:21:25
1.初始化一個webview(viewdidload)
@property (nonatomic, strong) WebViewJavascriptBridge *mainbridge;
UIWebView* webView = [[UIWebView alloc] initWithFrame:self.view.bounds];
[self.view addSubview:webView];
2.將此webview與WebViewJavascriptBridge關聯(viewdidload)
[WebViewJavascriptBridgeenableLogging];
self.mainbridge = [WebViewJavascriptBridgebridgeForWebView:weakSelf webViewDelegate:(WVJB_WEBVIEW_DELEGATE_TYPE*)weakSelf.delegatehandler:^(id data, WVJBResponseCallback responseCallback) {
根據data 就可以判斷了?
}
(3)oc給js傳值(通過?response接受返回值?)
[mainbridge send:@"A string sent from ObjC before Webview has loaded."responseCallback:^(id responseData) {
NSLog(@"objc got response! %@", responseData);
}];
?
6.swift?中AnyObject?轉string?轉?array
從json數組取得AnyObject? 類型的anyData
var?anyData:?AnyObject! = resultDic.objectForKey("wxts1")
轉string
var?Datatext:?String!?=?String(stringInterpolationSegment:?anyData)
轉array
1. ? ? ? ?let?DataArray: AnyObject! =?anyData?
2. ? ? ? ? ??var?DataArray:NSArray?= (anyData?as!?NSArray)?asArray?
7.在swift中使用oc庫
只要用到的是個.h ?文件
1.先創(chuàng)建一個.h文件,可命名為Bridging-Header.?h
2.?在build setting 中找到Object-C Bridging Header 中添加Bridging-Header.?h 的相對路徑
3.在?Bridging-Header.?h 中引入鎖需的三方庫或者oc類 ? 如:#import"AFNetworking.h"
8.NSString?打印為(null)贰您,為空判斷
NSString* remain_delivery_day = [resultDic?objectForKey:@"remain_delivery_day"]
服務器返回為空的話??remain_delivery_day便會輸出(null)坏平,
發(fā)現??remain_delivery_day isKindOfClass:[NSNull class]、[remain_delivery_day isEqualToString:@"(null)"] 都不可判斷其為空锦亦,==nil也不行
解決方案最常用的是?remain_delivery_day length]==0
還有[remain_delivery_day?isEqual:[NSNullnull]]??
其實明白:?nil是一個對象指針為空舶替,Nil是一個類指針為空,NULL是基本數據類型為空杠园。區(qū)別就是nil是一個對象顾瞪,而NULL只是一個值 ? 看這個問題就不是那么難了
9.放大一個imageview
#define CONST_animation_time?0.5
#define CONST_enlarge_proportion?15.0
CGPoint UpPointOfView(UIView *view)
{
return?(CGPoint){view.center.x,?200+2+55/2};
};
- (void) circleAnimate:(UIImageView*)view
{
CGContextRef context = UIGraphicsGetCurrentContext();
[UIView beginAnimations:nil?context:context];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:CONST_animation_time];
[view setCenter:UpPointOfView(view)];
CABasicAnimation *scalingAnimation = (CABasicAnimation *)[view.layer animationForKey:@"scaling"];
if?(!scalingAnimation)
{
scalingAnimation = [CABasicAnimation animationWithKeyPath:@"transform"];
scalingAnimation.repeatCount=1;
scalingAnimation.duration=CONST_animation_time;
scalingAnimation.autoreverses=NO;
scalingAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
scalingAnimation.fromValue=[NSValue valueWithCATransform3D:CATransform3DMakeScale(1.0,?1.0,?1.0)];
scalingAnimation.toValue=[NSValue valueWithCATransform3D:CATransform3DMakeScale(CONST_enlarge_proportion,CONST_enlarge_proportion,?1.0)];
}
[view.layer addAnimation:scalingAnimation forKey:@"scaling"];
view.layer.transform = CATransform3DMakeScale(CONST_enlarge_proportion,CONST_enlarge_proportion,?1.0);
[UIView commitAnimations];
}
10.利用手勢給圖片添加點擊事件
UITapGestureRecognizer?*singleTap = [[UITapGestureRecognizeralloc]initWithTarget:selfaction:@selector(imageviewclick)];
[imageview addGestureRecognizer:singleTap];//點擊圖片事件,
imageview.userInteractionEnabled = YES;
11.iOS偽表單上傳圖片
- (void) imageUpload:(UIImage?*) image{
//把圖片轉換成imageDate格式
NSData?*imageData =?UIImageJPEGRepresentation(image,?0.5);
//傳送路徑
NSString?*urlString =?@"http://www.呃呃呃呃呃.com/ImageUpload/uploadImg";
//建立請求對象
NSMutableURLRequest?* request = [[NSMutableURLRequestalloc]?init];
//設置請求路徑
[request?setURL:[NSURLURLWithString:urlString]];
//請求方式
[request?setHTTPMethod:@"POST"];
//一連串上傳頭標簽
NSString?*boundary = (NSString*)@"---------------------------14737809831466499882746641449";
NSString?*contentType = [NSStringstringWithFormat:@"multipart/form-data; boundary=%@",boundary];
[request?addValue:contentType?forHTTPHeaderField:?@"Content-Type"];
NSMutableData?*body = [NSMutableDatadata];
[body?appendData:[[NSStringstringWithFormat:@"\r\n--%@\r\n",boundary]dataUsingEncoding:NSUTF8StringEncoding]];
[body?appendData:[@"Content-Disposition: form-data; name=\"upfile\"; filename=\"bb\"\r\n"dataUsingEncoding:NSUTF8StringEncoding]];
[body?appendData:[@"Content-Type: application/octet-stream\r\n\r\n"dataUsingEncoding:NSUTF8StringEncoding]];
[body?appendData:[NSDatadataWithData:imageData]];
[body?appendData:[[NSStringstringWithFormat:@"\r\n--%@--\r\n",boundary]dataUsingEncoding:NSUTF8StringEncoding]];
[request?setHTTPBody:body];
//上傳文件開始
//+ (NSData *)sendSynchronousRequest:(NSURLRequest *)request returningResponse:(NSURLResponse **)response error:(NSError **)error;
NSData?*returnData = [NSURLConnectionsendSynchronousRequest:requestreturningResponse:nilerror:nil];
//獲得返回值
NSString?*returnString = [[NSStringalloc]?initWithData:returnDataencoding:NSUTF8StringEncoding];
NSData?*data = [returnString?dataUsingEncoding:NSUTF8StringEncoding];
NSDictionary?*resultDic = [NSJSONSerializationJSONObjectWithData:dataoptions:NSJSONReadingMutableLeaveserror:nil];
//? ? NSLog(@"%@",resultDic);
NSString?* str11 = [NSStringstringWithFormat:@",%@",[resultDicobjectForKey:@"img_url"]];
[urlImageHeadappendString:str11];
}
12.iOS簡單post
NSString *postString = [NSStringstringWithFormat:@" ? ? ? ? {\\"userName\\":\\"%@\\",\\"userPass\\":\\"%@\\",\\"version\\":\\"1.0\\"}",self.userField.text,self.passwordField.text];
NSLog(@"%@",postString);
//一般轉化稱UTF-8抛蚁,這里服務器需要ASCII
NSData* postData = [postStringdataUsingEncoding:NSASCIIStringEncodingallowLossyConversion:YES];
NSMutableURLRequest *request = [[[NSMutableURLRequestalloc] init] autorelease];
[requestsetURL:[NSURLURLWithString:@"http://lib.wap.zol.com.cn/test/login.php"]];
[requestsetCachePolicy:NSURLRequestUseProtocolCachePolicy];
[requestsetTimeoutInterval:100.0];
[request setHTTPMethod:@"POST"];
[request setHTTPBody:postData];
//?應該是application/x-www-form-urlencoded陈醒,但對方服務器寫成了appliction/x-www-form-urlencoded,告訴服務器是一個表單提交數據方式
[requestsetValue:@"appliction/x-www-form-urlencoded"forHTTPHeaderField:@"Content-Type"];
//得到提交數據的長度
NSString* len = [NSString stringWithFormat:@"%d", [postData length]];
//添加一個http包頭告訴服務器數據長度是多少
[requestsetValue:len forHTTPHeaderField:@"Content-Length"];
[NSURLConnectionconnectionWithRequest:request delegate:self];
13.iOS原生json解析
NSData *jsonData = [[NSData alloc] initWithContentsOfFile:JSON_PATH];
NSError *error =?nil;
id?jsonObject = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingAllowFragments error:&error;];
if?(jsonObject !=?nil?&& error ==?nil){
NSLog(@"Successfully deserialized...");
if?([jsonObject isKindOfClass:[NSDictionary?class]]){
NSDictionary *deserializedDictionary = (NSDictionary *)jsonObject;
NSLog(@"Dersialized JSON Dictionary = %@", deserializedDictionary);
}?elseif?([jsonObject isKindOfClass:[NSArray?class]]){
NSArray *deserializedArray = (NSArray *)jsonObject;
NSLog(@"Dersialized JSON Array = %@", deserializedArray);
}?else?{
NSLog(@"An error happened while deserializing the JSON data.");
}
}
14.模仿MBProgressHUD?成功
UIAlertView?*alert = [[UIAlertView alloc] initWithTitle:nil
message:[@"Alert"
delegate:nil
cancelButtonTitle:nil//NSLocalizedString(@"OK", @"OK") ? //
otherButtonTitles:nil];
//[alert setBounds:CGRectMake(alert.bounds.origin.x, alert.bounds.origin.y, alert.bounds.size.width, alert.bounds.size.height+30.0)];
[alert show];
UIActivityIndicatorView?*indicator = [[UIActivityIndicatorViewalloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
// Adjust the indicator so it is up a few pixels from the bottom of the alert
indicator.center = CGPointMake(alert.bounds.size.width/2,? alert.bounds.size.height-40.0);
[indicator startAnimating];
[alert insertSubview:indicator atIndex:0];
[indicator release];
[NSTimer scheduledTimerWithTimeInterval:3.0f
target:self
selector:@selector(dismissAlert:)
userInfo:[NSDictionary dictionaryWithObjectsAndKeys:alert,?@"alert",?@"testing ",?@"key"?,nil]??//nil.
repeats:NO];
NSLog(@"release alert");
[alert release];
-(void) dismissAlert:(NSTimer *)timer{
NSLog(@"release timer");
NSLog([[timer userInfo] objectForKey:@"key"]);
UIAlertView* alert = [[timer userInfo] objectForKey:@"alert"];
[alert dismissWithClickeonIndex:0?animated:YES];
}
//
[timer invalidate];
timer =?nil;
15.UITableView???滑動到某一行
創(chuàng)建NSIndexPath
NSIndexPath*scrollIndexPath?=[NSIndexPath?indexPathForRow:10?inSection:0];
自己的tableview開始滾動?
?[[self?tableView]?scrollToRowAtIndexPath:scrollIndexPath atScrollPosition:UITableViewScrollPositionTop?animated:YES];
16.常用小代碼
[[[UIApplication sharedApplication] keyWindow] endEditing:YES];//關閉鍵盤
取消cell的選中狀態(tài)cell.selectionStyle = UITableViewCellSelectionStyleNone;
狀態(tài)欄 ?? ? ? ? [[UIApplication sharedApplication]setStatusBarStyle:UIStatusBarStyleDefault];
self.navigationController.navigationBarHidden?= yes;?隱藏引導欄
17.關于Unbalanced?calls?to?begin/end?appearance?transitions?for
在自定義的tabbarvc里添加
- (void)viewWillAppear:(BOOL)animated
{
[self.selectedViewController beginAppearanceTransition: YES animated: animated];
}
-(void) viewDidAppear:(BOOL)animated
{
[self.selectedViewController endAppearanceTransition];
}
-(void) viewWillDisappear:(BOOL)animated
{
[self.selectedViewController beginAppearanceTransition: NO animated: animated];
}
-(void) viewDidDisappear:(BOOL)animated
{
[self.selectedViewController endAppearanceTransition];
}
18.CUICatalog:?Invalid?asset?name?supplied:?(null)
[UIImage?imageNamed:name];但是這個name卻是空的瞧甩,所以就報了這個錯了钉跷。
解決方法,在項目中搜索[UIImage?imageNamed:,然后打印看看所謂的name是否為空肚逸。找到后替換