1 【Network】使用AFNetworking2.0請求數據時出現錯誤Requestfailed:unacceptablecontent-type:text/html解決方法
使用AFNetworking 2.0 請求數據時出現錯誤 Request failed: unacceptablecontent-type: text/html 解決方法
添加一行
manager.responseSerializer.acceptableContentTypes= [NSSet setWithObject:@"text/html"];
http://www.haogongju.net/art/2407859
2 【JS】Js 常用調試的方法
http://www.cnblogs.com/Look_Sun/archive/2010/08/06/1793643.html
3 【JS】Safari調試工具
如何Enable - SafariPrefernces --> Advanced最下面的選項
勾選 然後你就可以在右鍵菜單上看到InspectElement選項了 - 跟Chrome一模一樣
4 【地理位置】APP獲取本地地理位置時注意
APP中獲取本地地理位置時,要注意打開APP的地理位置授權,位置在設置—>隱私—>定位服務
不然獲取不到位置信息,而且沒有提示,而且APP一旦移除重新安裝,需要重新設置。
5 【macox】mac命令行下怎麼切換到root用戶
可以使用sudo -i 然後輸入密碼即可
6 【js】遍歷js對象並獲取某一個成員對象
for(var app in callbackData)
{
var appObj = callbackData[app];
if(appObj != null && appObj.applianceId != undefined &&appObj.applianceId == curAppID)
{
_userApplianceInfo = appObj;
break;
}
}
7 Objective-C自定義NSLog宏
/*
XCode LLVM XXX - Preprocessing中Debug會添加 DEBUG=1 標誌
*/
#ifdef DEBUG
#define NSLog(FORMAT, ...) fprintf(stderr,"%s:%d\t%s\n",[[[NSString stringWithUTF8String:__FILE__] lastPathComponent] UTF8String], __LINE__, [[NSString stringWithFormat:FORMAT, ##__VA_ARGS__] UTF8String]);
#else
#define NSLog(FORMAT, ...) nil
#endif
8 【兼容性】IOS8中,CLLocationManagerDelegate不調用didUpdateLocations
CLLocationManagerDelegate不調用didUpdateLocations
http://www.cocoachina.com/bbs/read.php?tid=259171
iOS8下的開發變化
http://www.cocoachina.com/bbs/read.php?tid=217107
需要在使用CoreLocation前調用方法
requestWhenInUseAuthorization()
或者
requestAlwaysAuthorization()
並在Info.plist中加入兩個缺省沒有的字段
NSLocationAlwaysUsageDescription
NSLocationWhenInUseUsageDescription
9 計算指定時間與當前的時間差
計算指定時間與當前的時間差
http://blog.csdn.net/xinshou_jiaoming/article/details/7068328
計算指定時間與當前的時間差 比如,3天前、10分鐘前(這個在項目中經常遇到,所以記錄了下來)
以下是實現方法:
/**
*計算指定時間與當前的時間差
*@paramcompareDate 某一指定時間
*@return多少(秒or分or天or月or年)+前 (比如,3天前、10分鐘前)
*/
+(NSString *) compareCurrentTime:(NSDate*) compareDate
//
{
NSTimeInterval timeInterval = [compareDate timeIntervalSinceNow];
timeInterval = -timeInterval;
long temp = 0;
NSString *result;
if (timeInterval < 60) {
result = [NSStringstringWithFormat:@"剛剛"];
}
elseif((temp = timeInterval/60) <60){
result = [NSStringstringWithFormat:@"%d分前",temp];
}
elseif((temp = temp/60) <24){
result = [NSStringstringWithFormat:@"%d小前",temp];
}
elseif((temp = temp/24) <30){
result = [NSStringstringWithFormat:@"%d天前",temp];
}
elseif((temp = temp/30) <12){
result = [NSStringstringWithFormat:@"%d月前",temp];
}
else{
temp = temp/12;
result = [NSStringstringWithFormat:@"%d年前",temp];
}
return result;
}
以下是NSDate中的常用方法:
/**
- (id)initWithTimeInterval:(NSTimeInterval)secs sinceDate:(NSDate*)refDate;
初始化爲以refDate爲基準,然後過了secs秒的時間
- (id)initWithTimeIntervalSinceNow:(NSTimeInterval)secs;
初始化爲以當前時間爲基準,然後過了secs秒的時間
- (NSTimeInterval)timeIntervalSinceDate:(NSDate *)refDate;
以refDate爲基準時間,返回實例保存的時間與refDate的時間間隔
- (NSTimeInterval)timeIntervalSinceNow;
以當前時間(Now)爲基準時間,返回實例保存的時間與當前時間(Now)的時間間隔
- (NSTimeInterval)timeIntervalSince1970;
以1970/01/01 GMT爲基準時間,返回實例保存的時間與1970/01/01 GMT的時間間隔
- (NSTimeInterval)timeIntervalSinceReferenceDate;
以2001/01/01 GMT爲基準時間,返回實例保存的時間與2001/01/01 GMT的時間間隔
+ (NSTimeInterval)timeIntervalSinceReferenceDate;
*/
//秒
// - (NSTimeInterval)timeIntervalSinceNow;
// 以當前時間(Now)爲基準時間,返回實例保存的時間與當前時間(Now)的時間間隔
10 IOS開發常用數學函數
1、 三角函數
double sin (double);正弦
double cos (double);餘弦
double tan (double);正切
2 、反三角函數
double asin (double); 結果介於[-PI/2,PI/2]
double acos (double); 結果介於[0,PI]
double atan (double); 反正切(主值), 結果介於[-PI/2,PI/2]
double atan2 (double,double); 反正切(整圓值), 結果介於[-PI,PI]
3 、雙曲三角函數
double sinh (double);
double cosh (double);
double tanh (double);
4 、指數與對數
double exp (double);求取自然數e的冪
double sqrt (double);開平方
double log (double); 以e爲底的對數
double log10 (double);以10爲底的對數
double pow(double x, double y);計算以x爲底數的y次冪
float powf(float x, float y);功能與pow一致,只是輸入與輸出皆爲浮點數
5 、取整
double ceil (double); 取上整
double floor (double); 取下整
6 、絕對值
double fabs (double);求絕對值
double cabs(struct complexznum) ;求複數的絕對值
7 、標準化浮點數
double frexp (double f, int*p); 標準化浮點數, f= x * 2^p, 已知f求x,p ( x介於[0.5,1] )
double ldexp (double x, intp); 與frexp相反, 已知x, p求f
8 、取整與取餘
double modf (double,double*); 將參數的整數部分通過指針回傳, 返回小數部分
double fmod (double, double);返回兩參數相除的餘數
9 、其他
double hypot(double x, doubley);已知直角三角形兩個直角邊長度,求斜邊長度
double ldexp(double x, intexponent);計算x*(2的exponent次冪)
double poly(double x, intdegree, double coeffs [] );計算多項式
nt matherr(struct exception*e);數學錯誤計算處理程序
轉載:http://blog.csdn.net/zyc851224/article/details/7843859
11 IOS獲取屏幕尺寸與分辨率
IOS獲取屏幕分辨率
http://blog.csdn.net/tangaowen/article/details/7597535
獲取屏幕分辨率是個很有用的功能,尤其在一些遊戲相關的開發中,圖形的繪製與屏幕分辨率密不可分。得到當前屏幕的分辨率是必不可少的支持。
獲取屏幕分辨率可以兩步走
1、得到當前屏幕的尺寸:
CGRect rect_screen = [[UIScreenmainScreen]bounds];
CGSize size_screen= rect_screen.size;
2、獲得scale:
CGFloat scale_screen = [UIScreenmainScreen].scale;
此時屏幕尺寸的寬高與scale的乘積就是相應的分辨率值。
12 iPhone開發分辨率
1.iPhone5分辨率320x568,像素640x1136,@2x
2.iPhone6分辨率375x667,像素750x1334,@2x
3.iPhone6Plus分辨率414x736,像素1242x2208,@3x
這裏所注的都是已經添加相關尺寸loading圖後的開發分辨率和像素數,其中iphone6plus最終的物理分辨率會被蘋果自動縮放到1080p(縮放比例1.14)。
iPhone6分辨率與適配
http://www.cocoachina.com/ios/20140912/9601.html
13 【編譯】Cannot assign to 'self'outside of a method in the init family
有時候我們重寫父類的init方法時不注意將init後面的第一個字母寫成了小寫,在這個方法裏面又調用父類的初始化方法(self= [super init];)時會報錯,錯誤信息如下:error:Cannot assign to 'self' outside of a methodin the init family
原因:只能在init方法中給self賦值,Xcode判斷是否爲init方法規則:方法返回id,並且名字以init+大寫字母開頭+其他 爲準則。例如:-(id) initWithXXX;
出錯代碼:-(id) Myinit{
self = [super init];
……
}
解決方法:-(id) initWithMy
{
self = [super init];
}
如下代碼:
僅僅因爲大小寫問題,將initWithDelegate寫成了-(id) initwithDelegate,就會報錯
14 CoreData臨時實體對象
NSEntityDescription *entity = [NSEntityDescription entityForName:NSStringFromClass([IMUserInfoEntity class]) inManagedObjectContext:[[IMDataModelCoreDataStorage shareInstance] mainThreadManagedObjectContext]];
IMUserInfoEntity *userTmpEntity = [[IMUserInfoEntity alloc] initWithEntity:entityinsertIntoManagedObjectContext:nil];
15 【Storyboard】在Storyboard中添加子View後,頁面控件不顯示問題
問題:
在Storyboard的一個ViewController中添加子View後,再在代碼中新建一個子View來替代此View,導致在代碼中添加按鈕控件,按鈕不顯示,但是可以接收到按鈕事件。
//初始化地圖View
if (!_bMapView) {
_bMapView = [[BMKMapView alloc] initWithFrame:CGRectMake(0, 20, SCREEN_BOUNDS.size.width, SCREEN_BOUNDS.size.height * 0.05)];//300 [[BMKMapView alloc]initWithFrame:CGRectMake(0, 0, 320, 480)];
}
self.mapView = _bMapView;
if (![self.view.subviews containsObject:self.mapView]) {
[self.view addSubview:self.mapView];
}
UIButton *_provinceButton = [[UIButton alloc] initWithFrame:CGRectMake(120, 120, 100, 40)];
_provinceButton.titleLabel.text = @"TestButton";
_provinceButton.titleLabel.textColor = [UIColor yellowColor];
[_provinceButton addTarget:self action:@selector(TestprovinceButtonClicked:)forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:_provinceButton];
解決方案:
在Storyboard的ViewController中添加的子View已經實例化了,通過簡單地替換操作,不會使其實例自動釋放,因爲已經作爲子View,添加進ViewController所在的View中了。需要手動先將其從SuperView移除,然後再重新添加新View的實例。
//初始化地圖View
if (!_bMapView) {
_bMapView = [[BMKMapView alloc] initWithFrame:CGRectMake(0, 20, SCREEN_BOUNDS.size.width, SCREEN_BOUNDS.size.height * 0.05)];//300 [[BMKMapView alloc]initWithFrame:CGRectMake(0, 0, 320, 480)];
}
if (self.mapView) {
[self.mapView removeFromSuperview];
}
self.mapView = _bMapView;
if (![self.view.subviews containsObject:self.mapView]) {
[self.view addSubview:self.mapView];
}
16 【控件】UIButton控件文字不顯示
//此行頁面不會顯示文字
_provinceButton.titleLabel.text = @"TestButton";
//此行頁面顯示文字
[_provinceButton setTitle:@"Test1" forState:UIControlStateNormal];
17 【CoreData】like查詢
查詢不到結果寫法
// NSPredicate*predicate=[NSPredicate predicateWithFormat:@"province LIKE '%@?' AND cityLIKE '%@?' AND county =%@",tempEntity.province,tempEntity.city,tempEntity.county];
可查詢到結果寫法:
NSString *predStr = [NSString stringWithFormat:@"provinceLIKE \'%@?\' AND city LIKE \'%@?\' AND county = \'%@\'",tempEntity.province,tempEntity.city,tempEntity.county];
NSPredicate*predicate=[NSPredicate predicateWithFormat:predStr];
NSString * predStr = [NSString stringWithFormat:@"provinceLIKE \'%@%%\' AND city LIKE \'%@%%\' AND county = \'%@\'",tempEntity.province,tempEntity.city,tempEntity.county];
18 iOS字符串 中包含 % 百分號的方法
百分號的轉換,NSString中需要格式化的字符串中百分號使用%%表示,而char*中百分號也是使用%%表示。
例如:NSLog(@"%%%@%%",@"hello"),控制檯會打印出%hello%。
19 【UILabel】自適應高度和自動換行
1. //初始化label
2. UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0,0,0,0)];
3. //設置自動行數與字符換行
4. [label setNumberOfLines:0];
5. label.lineBreakMode = UILineBreakModeWordWrap;
6. // 測試字串
7. NSString *s = @"這是一個測試!!!adsfsaf時發生發勿忘我勿忘我勿忘我勿忘我勿忘我阿阿阿阿阿阿阿阿阿阿阿阿阿啊00000000阿什頓。。。";
8. UIFont *font = [UIFont fontWithName:@"Arial" size:12];
9. //設置一個行高上限
10. CGSize size = CGSizeMake(320,2000);
11. //計算實際frame大小,並將label的frame變成實際大小
12. CGSize labelsize = [s sizeWithFont:font constrainedToSize:size lineBreakMode:UILineBreakModeWordWrap];
13. [label setFrame:CGRectMake:(0,0, labelsize.width, labelsize.height)];
IOS7以上做法
http://www.tuicool.com/articles/eYbAv2
UILabel自適應高度和自動換行
http://blog.csdn.net/csj1987/article/details/6662852
iOS學習5:UILabel的使用
http://bbs.9ria.com/thread-244444-1-1.html
20 Mac上顏色提取工具
很多人有這個需求:把鼠標放在一個點上,顯示該點顏色的RGB值。其實蘋果電腦的Mac OS X系統就自帶鼠標所在點顏色RGB值查看工具:數碼測色計,只是藏得比較深罷了。打開Finder(Dock欄第一個笑臉圖標),選擇應用程序--實用工具--數碼測色計,雙擊即可啓動。
3 N6 ?: ?: a9 n(s* n 七度蘋果電腦軟件
$ U4 a0 _# W* \7N 七度蘋果電腦軟件
數碼測色計界面截圖
這個界面大家都能看懂了吧,中間是預覽鼠標所處位置得像素,右側顯示顏色RGB值,取點範圍大小可以通過滑動條來調節。
& v# u$ |# W0t( h2 {' S 七度蘋果電腦軟件
+ }* v) C9K" b2 `7 J 七度蘋果電腦軟件
在數碼測色計得下拉菜單裏選擇RGB數值模式,有“255,255,255”那種,也有“0000FF”那種8 r% E F Z( E8 t# k 七度蘋果電腦軟件
* N& _+ k) [9w 七度蘋果電腦軟件
OK,說完了,很簡潔的一個蘋果Mac OS X系統自帶工具,但很有用。嫌它“埋”得太深,可以直接拖到上級得“應用程序”目錄裏(Mac的精華就是“想拖就拖”)。Enjoy your Mac