全系列文章索引:
1 【SQL】附加數(shù)據(jù)庫(kù)5120錯(cuò)誤(拒絕訪問(wèn))處理方法
http://jingyan.baidu.com/article/c1a3101e8b34c2de656debbe.html
????右鍵需要附加的數(shù)據(jù)庫(kù)文件部凑,彈出屬性對(duì)話框,選擇安全標(biāo)簽頁(yè)。找到Authenticated Users用戶名。如未找到,進(jìn)行Authenticated Users用戶名的添加识补。
2 【UI】'-[UITableViewControllerloadView] loaded the "XXX" nib but didn't get a UITableView.'
'-[UITableViewController loadView] loaded the"XXX" nib but didn't get a UITableView.'
解決方法:在頭文件中,將所繼承的父類(lèi)UITableViewController 改成 UIViewController。
3 linux/mac vi命令詳解
linux/mac vi命令詳解
http://blog.csdn.net/youngkingyj/article/details/22713965
4 IOS獲取最新設(shè)備型號(hào)方法
方法:
#import "sys/utsname.h”
struct?utsname?systemInfo;
uname(&systemInfo);
NSString?*deviceString?=?[NSString?stringWithCString:systemInfo.machine?encoding:NSUTF8StringEncoding];?
http://blog.csdn.net/luoyeffcs/article/details/18610839
5 objective-c ASCII NSString轉(zhuǎn)換
objective-c ASCII NSString轉(zhuǎn)換--分享
// NSString to ASCII
NSString *string = @"A";
int asciiCode = [string characterAtIndex: 0]; //65
//ASCII to NSString
int asciiCode = 65;
NSString *string =[NSString stringWithFormat: @"%c",asciiCode];? //A
來(lái)源http://blog.sina.com.cn/s/blog_63aaf4690100w981.html
中文字符ASCII碼和NSString相互轉(zhuǎn)換
http://www.2cto.com/kf/201309/243443.html
6 【UI】UIButton文字居左顯示
UIButton *btn = [[UIButton alloc] init];
btn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
7 【網(wǎng)絡(luò)】AFNetwork2.0在請(qǐng)求時(shí)報(bào)錯(cuò)code=-1016和3840
http://blog.csdn.net/huifeidexin_1/article/details/38844535
????在進(jìn)行網(wǎng)絡(luò)請(qǐng)求時(shí)出現(xiàn)-1016是因?yàn)橹恢С謙ext/json税产,application/json,text/javascript,你可以添加text/html 砖第,一勞永逸的方法是在AFURLResponseSerialization.h里面搜索self.acceptableContentTypes撤卢,然后在里面添加@"text/html",@"text/plain"。這樣就可以解決-1016的錯(cuò)誤了梧兼,但是隨之而來(lái)的是3840錯(cuò)誤放吩。
Error?Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed.
(Cocoa error 3840.)" (JSON text did not start with array or object and
option to allow fragments not set.) UserInfo=0x9152780 {NSDebugDescription=JSON
text did not start with array or object and option to allow fragments not set.}
你會(huì)發(fā)現(xiàn)出現(xiàn)此錯(cuò)誤
怎么辦呢?
添加如下語(yǔ)句 就可以解決問(wèn)題了
manger.requestSerializer?= [AFHTTPRequestSerializer serializer];
manger.responseSerializer?= [AFHTTPResponseSerializer serializer];
????????是否成功了,成功了吧!但是新問(wèn)題出現(xiàn)了——編碼問(wèn)題羽杰。如果服務(wù)器返回a的話渡紫,你收到的是<61>,這樣怎么能行呢考赛。當(dāng)你用瀏覽器去請(qǐng)求時(shí)發(fā)現(xiàn)響應(yīng)頭Content-Type: text/html;charset=UTF-8是這樣的惕澎,但是afNetwork 請(qǐng)求是Content-Type:text/plain;charset=ISO-8859-1。為什么pc瀏覽器訪問(wèn)的和用afNetwork訪問(wèn)的不一致呢? 接著發(fā)現(xiàn)其實(shí)添加如下二句即可颜骤,也不用去修改AFURLResponseSerialization.h 里面的東西
manger.requestSerializer?= [AFHTTPRequestSerializer serializer];
manger.responseSerializer?= [AFHTTPResponseSerializer serializer];
????????把收到的responseObject 轉(zhuǎn)換一下編碼就OK了唧喉。
NSData*doubi= responseObject;
NSString?*shabi =? [[NSString?alloc]initWithData: doubi?encoding: NSUTF8StringEncoding];
8 【JSON】NSDictionary與NSString互轉(zhuǎn)
NSString *str = [dataDic JSONRepresentation];
NSDictionary *resultDic = [htmStr JSONValue];
9 【UI】在UIImageView中添加子按鈕無(wú)法響應(yīng)事件問(wèn)題
問(wèn)題分析:
?????? UIImageView默認(rèn)是不接受事件響應(yīng)的userInteractionEnabled=NO,所以用戶點(diǎn)擊操作在該控件即被截停了忍抽,無(wú)法往子控件中傳遞八孝,故需要開(kāi)啟userInteractionEnabled屬性為true,以使事件往下傳遞鸠项。
_scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
??? _scrollView.delegate = self;
//??? scrollView.userInteractionEnabled = YES;
??? [self.view addSubview: _scrollView];
??? _activityIndicatorView = [MDViewUtility createActivityIndicatorViewInView: self.view];
??? UIImageView *backImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 200)];
??? [backImageView setImage: [UIImage imageNamed: @"MyCenter_BackgroundImage"]];
??? //這一句很重要干跛,不然事件無(wú)法往下傳遞
??? backImageView.userInteractionEnabled = YES;
??? [_scrollView addSubview: backImageView];
??? _myAccountView = [[MDMyAccountView alloc] initWithFrame: CGRectMake(self.view.frame.size.width/2 - 50, 0, 100, 200) WithVM: _myAccountVM];
??? [backImageView addSubview: _myAccountView];
??? [_myAccountView.myScoreButton addTarget: self action: @selector(myScoreButtonClicked:) forControlEvents: UIControlEventTouchUpInside];
??? UITapGestureRecognizer *singleTap1 = [[UITapGestureRecognizer alloc] initWithTarget: self action: @selector(myScoreButtonClicked:)];
??? singleTap1.delegate = self;
??? [_myAccountView.myPhotoImageView setUserInteractionEnabled: YES];
??? [_myAccountView.myPhotoImageView addGestureRecognizer: singleTap1];
??? UITapGestureRecognizer *singleTap2 = [[UITapGestureRecognizer alloc] initWithTarget: self action: @selector(myScoreButtonClicked:)];
??? singleTap2.delegate = self;
??? [_myAccountView.myNeedLoginLabel setUserInteractionEnabled: YES];
??? [_myAccountView.myNeedLoginLabel addGestureRecognizer: singleTap2];
10 【UI】在二級(jí)頁(yè)面中隱藏Tabbar
在VC初始化時(shí)設(shè)置屬性:
self.hidesBottomBarWhenPushed=YES;
11 Cocoa/Cocoa.hfile not found
Cocoa/Cocoa.h file not found
????創(chuàng)建OC類(lèi)時(shí),有時(shí)OC類(lèi)會(huì)自動(dòng)包含了文件頭#import <Cocoa/Cocoa.h>,這時(shí)報(bào)錯(cuò):‘Cocoa/Cocoa.h' file not found祟绊,這個(gè)問(wèn)題是因?yàn)镃ocoa/Cocoa.h為OSX的庫(kù)文件楼入,而不時(shí)IOS的庫(kù)文件,將其修改為#import <UIKit/UIKit.h>問(wèn)題解決牧抽。
????不過(guò)嘉熊,所有用到NS***的都要修改為UI***
12 JSONKITisa錯(cuò)誤的解決辦法
轉(zhuǎn)載:http://blog.csdn.net/hemuhan/article/details/17753453
????????在開(kāi)發(fā)IOS的時(shí)候,好多第三方庫(kù)使用JSONKIT這個(gè)庫(kù)阎姥,在IOS6.0以上的版本編譯的話记舆,會(huì)提示 Semantic Issue錯(cuò)誤。
????????錯(cuò)誤顯示:direct access to Objective-C's isa is deprecated in favorof object_getClass()
????????看資料說(shuō)是 使用 array->isa 這個(gè)棄用的函數(shù)呼巴,網(wǎng)上查大部分的資料都說(shuō)要使用object_getClass 和object_setClass來(lái)更正泽腮。
????????看到Bee中Demo沒(méi)有更改這個(gè)函數(shù),花費(fèi)很長(zhǎng)時(shí)間終于整明白了如果使IOS不報(bào)這個(gè)錯(cuò)誤
從項(xiàng)目中搜索 Direct usage of 'isa' 將 YES(treat as error) 改為NO 就可以了
13 【URL】創(chuàng)建并保存Cookie的方法
NSString*cookieString = [NSString stringWithString: [headers objectForKey: @"Cookie"]];
NSMutableDictionary *cookieProperties = [[NSMutableDictionary alloc]init];
[cookieProperties setValue: cookieString forKey:NSHTTPCookieValue];
[cookieProperties setValue:@"QQCookie"forKey:NSHTTPCookieName];
[cookieProperties setValue:@".QQ.com"forKey:NSHTTPCookieDomain];
[cookieProperties setValue:[NSDate dateWithTimeIntervalSinceNow: 60*60] forKey: NSHTTPCookieExpires];
[cookieProperties setValue:@"/" forKey: NSHTTPCookiePath];
NSHTTPCookie *newcookie = [[NSHTTPCookie alloc] initWithProperties: cookieProperties];
[[NSHTTPCookieStorage sharedHTTPCookieStorage] setCookie: newcookie];
http://ios-iphone.diandian.com/post/2011-09-20/5175529
14 NSDictionary判斷空
字典里某個(gè)鍵key的值可能是空數(shù)組~~~那這個(gè)[dic objectForkey:key]是什么衣赶?
你猜會(huì)是[NSNull null]诊赊?
也可能不是~~~但至少是個(gè)空數(shù)組。
[[dic objectForkey:key] count]會(huì)告訴我們結(jié)果府瞄。
????????下面的代碼使用了NSNull來(lái)判斷字典某個(gè)鍵的值是否為空碧磅。但是這種判斷方法碘箍,似乎對(duì)于空集合類(lèi)不大奏效。
id?object?=?nil;
//?判斷對(duì)象不為空
if(object)?{
}
//?判斷對(duì)象為空
if(object?==?nil)?{
}
//?數(shù)組初始化鲸郊,空值結(jié)束
NSArray?*array?=?[[NSArray?alloc]?initWithObjects:@"First",?@"Second",?nil];
//?判斷數(shù)組元素是否為空
NSString?*element?=?[array?objectAtIndex:2];
if((NSNull?*)element?==?[NSNull?null])?{
}
//?判斷字典對(duì)象的元素是否為空
NSDictionary?*dictionary?=?[NSDictionary?dictionaryWithObjectsAndKeys:? ? @"iPhone",?@"First",?@"iPad",?@"Second",?nil];
NSString?*value?=?[dictionary?objectForKey:@"First"];
if((NSNull?*)value?==?[NSNull?null])?{
}
15 NSDate格式化輸出
NSDate*date = [NSDate dateWithTimeIntervalSince1970: [[MDMyUserInfoEntity shareInstance] birthday]];
NSDateFormatter*dateFormatter = [[NSDateFormatter alloc] init];
//設(shè)定時(shí)間格式,這里可以設(shè)置成自己需要的格式
[dateFormatter setDateFormat:@"yyyy-MM-dd"];
//用[NSDate date]可以獲取系統(tǒng)當(dāng)前時(shí)間
NSString *currentDateStr = [dateFormatter stringFromDate: date];
16 AFNetworking請(qǐng)求HTTPS時(shí)發(fā)生code=-1012的錯(cuò)誤
????????AFNetworking 2.0在請(qǐng)求HTTPS資源的時(shí)候丰榴,總是發(fā)生如下錯(cuò)誤:
self.securityPolicy = [AFSecurityPolicy policyWithPinningMode: AFSSLPinningModeNone];
//解決“Error Domain=NSURLErrorDomain Code=-1012
"The operation couldn’t be completed.”的問(wèn)題,AFNetworking 2.0默認(rèn)在檢查SSL證書(shū)的時(shí)候比較嚴(yán)格self.securityPolicy.allowInvalidCertificates = YES;
解決辦法就是允許使用無(wú)效的證書(shū)秆撮。
17 字符串NSString中去掉空格
在ios開(kāi)發(fā)中?stringByTrimmingCharactersInSet函數(shù)可以用來(lái)去掉字符串中的任意字符四濒。
例如:
NSString *string1 = @" ? 11 ?1 ?";
NSString *string2 = [string1?stringByTrimmingCharactersInSet [NSCharacterSet whitespaceAndNewlineCharacterSet]];
這個(gè)時(shí)候string2的結(jié)果是"11 1"
(去處空格的時(shí)候只是去除字符串中最前和最后的字符。)
【iOS】字符串NSString中去掉空格
http://blog.csdn.net/chenyong05314/article/details/8752654
NSString過(guò)濾字符串
http://blog.sina.com.cn/s/blog_5d2698930100wxvw.html
18 AFNetworking請(qǐng)求未發(fā)出去返回一堆html代碼
網(wǎng)絡(luò)請(qǐng)求中职辨,域名指向的IP地址錯(cuò)了
19 MBProgressHud顯示多行文本
+(void) showToastInView:(UIView *)view WithText:(NSString *) text WithDelay:(NSTimeInterval)delay
{
??? MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo: view animated: YES];
??? hud.mode = MBProgressHUDModeText;
????//??? hud.labelText = text;
??? hud.detailsLabelText=text;
??? hud.detailsLabelFont = [UIFont fontWithName:@"Helvetica" size:16];
??? hud.detailsLabelColor = [UIColor whiteColor];
??? hud.margin = 10.f;
??? hud.yOffset = 0;
??? hud.alpha = 0.7;
??? hud.removeFromSuperViewOnHide = YES;
??? [hudhide:YES afterDelay:delay];
}
20 nestedpush animation can result in corrupted navigation bar
nested push animation can result in corrupted navigation bar.
Finishing up a navigation transition in an unexpected state.Navigation Bar subview tree might get corrupted.
【iphone】返回崩潰:nested pop animation canresult in corrupted navigation bar nested pop animation can re