全系列文章索引:
1 【SQL】附加數據庫5120錯誤(拒絕訪問)處理方法
http://jingyan.baidu.com/article/c1a3101e8b34c2de656debbe.html
右鍵需要附加的數據庫文件,彈出屬性對話框,選擇安全標籤頁。找到Authenticated Users用戶名。如未找到,進行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.'
解決方法:在頭文件中,將所繼承的父類UITableViewController 改成 UIViewController。
3 linux/mac vi命令詳解
linux/mac vi命令詳解
http://blog.csdn.net/youngkingyj/article/details/22713965
4 IOS獲取最新設備型號方法
方法:
#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轉換
objective-c ASCII NSString轉換--分享
// 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
來源http://blog.sina.com.cn/s/blog_63aaf4690100w981.html
中文字符ASCII碼和NSString相互轉換
http://www.2cto.com/kf/201309/243443.html
6 【UI】UIButton文字居左顯示
UIButton *btn = [[UIButton alloc] init];
btn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
7 【網絡】AFNetwork2.0在請求時報錯code=-1016和3840
http://blog.csdn.net/huifeidexin_1/article/details/38844535
在進行網絡請求時出現-1016是因爲只支持text/json,application/json,text/javascript,你可以添加text/html ,一勞永逸的方法是在AFURLResponseSerialization.h裏面搜索self.acceptableContentTypes,然後在裏面添加@"text/html",@"text/plain"。這樣就可以解決-1016的錯誤了,但是隨之而來的是3840錯誤。
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.}
你會發現出現此錯誤
怎麼辦呢?
添加如下語句 就可以解決問題了
manger.requestSerializer = [AFHTTPRequestSerializer serializer];
manger.responseSerializer = [AFHTTPResponseSerializer serializer];
是否成功了,成功了吧!但是新問題出現了——編碼問題。如果服務器返回a的話,你收到的是<61>,這樣怎麼能行呢。當你用瀏覽器去請求時發現響應頭Content-Type: text/html;charset=UTF-8是這樣的,但是afNetwork 請求是Content-Type:text/plain;charset=ISO-8859-1。爲什麼pc瀏覽器訪問的和用afNetwork訪問的不一致呢? 接着發現其實添加如下二句即可,也不用去修改AFURLResponseSerialization.h 裏面的東西
manger.requestSerializer = [AFHTTPRequestSerializer serializer];
manger.responseSerializer = [AFHTTPResponseSerializer serializer];
把收到的responseObject 轉換一下編碼就OK了。
NSData*doubi= responseObject;
NSString *shabi = [[NSString alloc]initWithData: doubi encoding: NSUTF8StringEncoding];
8 【JSON】NSDictionary與NSString互轉
NSString *str = [dataDic JSONRepresentation];
NSDictionary *resultDic = [htmStr JSONValue];
9 【UI】在UIImageView中添加子按鈕無法響應事件問題
問題分析:
UIImageView默認是不接受事件響應的userInteractionEnabled=NO,所以用戶點擊操作在該控件即被截停了,無法往子控件中傳遞,故需要開啓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"]];
//這一句很重要,不然事件無法往下傳遞
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】在二級頁面中隱藏Tabbar
在VC初始化時設置屬性:
self.hidesBottomBarWhenPushed=YES;
11 Cocoa/Cocoa.hfile not found
Cocoa/Cocoa.h file not found
創建OC類時,有時OC類會自動包含了文件頭#import <Cocoa/Cocoa.h>,這時報錯:‘Cocoa/Cocoa.h' file not found,這個問題是因爲Cocoa/Cocoa.h爲OSX的庫文件,而不時IOS的庫文件,將其修改爲#import <UIKit/UIKit.h>問題解決。
不過,所有用到NS***的都要修改爲UI***
12 JSONKITisa錯誤的解決辦法
轉載:http://blog.csdn.net/hemuhan/article/details/17753453
在開發IOS的時候,好多第三方庫使用JSONKIT這個庫,在IOS6.0以上的版本編譯的話,會提示 Semantic Issue錯誤。
錯誤顯示:direct access to Objective-C's isa is deprecated in favorof object_getClass()
看資料說是 使用 array->isa 這個棄用的函數,網上查大部分的資料都說要使用object_getClass 和object_setClass來更正。
看到Bee中Demo沒有更改這個函數,花費很長時間終於整明白瞭如果使IOS不報這個錯誤
從項目中搜索 Direct usage of 'isa' 將 YES(treat as error) 改爲NO 就可以了
13 【URL】創建並保存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判斷空
字典裏某個鍵key的值可能是空數組~~~那這個[dic objectForkey:key]是什麼?
你猜會是[NSNull null]?
也可能不是~~~但至少是個空數組。
[[dic objectForkey:key] count]會告訴我們結果。
下面的代碼使用了NSNull來判斷字典某個鍵的值是否爲空。但是這種判斷方法,似乎對於空集合類不大奏效。
id object = nil;
// 判斷對象不爲空
if(object) {
}
// 判斷對象爲空
if(object == nil) {
}
// 數組初始化,空值結束
NSArray *array = [[NSArray alloc] initWithObjects:@"First", @"Second", nil];
// 判斷數組元素是否爲空
NSString *element = [array objectAtIndex:2];
if((NSNull *)element == [NSNull null]) {
}
// 判斷字典對象的元素是否爲空
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];
//設定時間格式,這裏可以設置成自己需要的格式
[dateFormatter setDateFormat:@"yyyy-MM-dd"];
//用[NSDate date]可以獲取系統當前時間
NSString *currentDateStr = [dateFormatter stringFromDate: date];
16 AFNetworking請求HTTPS時發生code=-1012的錯誤
AFNetworking 2.0在請求HTTPS資源的時候,總是發生如下錯誤:
self.securityPolicy = [AFSecurityPolicy policyWithPinningMode: AFSSLPinningModeNone];
//解決“Error Domain=NSURLErrorDomain Code=-1012
"The operation couldn’t be completed.”的問題,AFNetworking 2.0默認在檢查SSL證書的時候比較嚴格self.securityPolicy.allowInvalidCertificates = YES;
解決辦法就是允許使用無效的證書。
17 字符串NSString中去掉空格
在ios開發中 stringByTrimmingCharactersInSet函數可以用來去掉字符串中的任意字符。
例如:
NSString *string1 = @" 11 1 ";
NSString *string2 = [string1 stringByTrimmingCharactersInSet [NSCharacterSet whitespaceAndNewlineCharacterSet]];
這個時候string2的結果是"11 1"
(去處空格的時候只是去除字符串中最前和最後的字符。)
【iOS】字符串NSString中去掉空格
http://blog.csdn.net/chenyong05314/article/details/8752654
NSString過濾字符串
http://blog.sina.com.cn/s/blog_5d2698930100wxvw.html
18 AFNetworking請求未發出去返回一堆html代碼
網絡請求中,域名指向的IP地址錯了
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
http://blog.csdn.net/lengshengren/article/details/12616217