我是 java & php 程序員,遇到了坑爹的iPhone,被逼無奈在崩潰的邊緣下學習object-c ,在學習中遇到了不少 奇葩,無知,齷蹉,嘔吐的問題(弱弱的說 : 有的些問題到如今還不知道具體的原理)故此把開發中全部遇到的問題,和須要使用的開源庫 一一記載下來,爲那些苦B的要學習OBJECT-C的屌絲們加點料吧。本文純粹記錄性遊記類文章,學術性觀摩團請繞行,專家請繞行。在編寫過程當中避免不了出現問題或者遺漏問題,但願你們多多指點與板磚! php
https://github.com/pokeb/asi-http-request html
引入頭文件 #import "ASIHTTPRequest.h" java
更詳細的使用方法請參照:http://www.cnblogs.com/zhwl/archive/2012/07/14/2591752.html git
- (void)viewDidLoad { [super viewDidLoad]; //請求的後臺活動列表 NSURL *url = [NSURL URLWithString:@"http://m.weather.com.cn/data/101180701.html"]; ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url]; [request setDelegate:self]; [request startAsynchronous]; } //異步請求開始 - (void)requestStarted:(ASIHTTPRequest *)request { NSLog(@"request start :%@", @"start"); } //異步請求結束 - (void)requestFinished:(ASIHTTPRequest *)request { // Use when fetching text data NSString *jsonString = [request responseString]; NSLog (@"Response JSON :%@", jsonString); } //異步請求錯誤 - (void)requestFailed:(ASIHTTPRequest *)request { // NSError *error = [request error]; NSLog (@"Response JSON :%@", @"error"); }
https://github.com/stig/json-framework 程序員
解壓後把相應的文件導入到工程中,還沒有發現問題 github
在1-3的小試牛刀中,咱們請求了有關天氣的URL,這個URL會有一個JSON的相應,咱們繼續1-3,來解解析這個響應的JSON json
- (void)viewDidLoad { [super viewDidLoad]; //請求的後臺活動列表 //NSURL *url = [NSURL URLWithString:@"http://192.168.1.4/beer/?cat=2&json=1"]; NSURL *url = [NSURL URLWithString:@"http://m.weather.com.cn/data/101180701.html"]; ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url]; [request setDelegate:self]; [request startAsynchronous]; } //異步請求開始 - (void)requestStarted:(ASIHTTPRequest *)request { NSLog(@"request start :%@", @"start"); } //異步請求結束 - (void)requestFinished:(ASIHTTPRequest *)request { NSString *jsonString = [request responseString]; NSLog (@"Response JSON :%@", jsonString); SBJsonParser *parser =[[SBJsonParser alloc] init]; NSDictionary *rootDic = [parser objectWithString:jsonString]; NSDictionary *weatherInfo = [rootDic objectForKey:@"weatherinfo"]; NSLog (@"Response JSON city :%@", [weatherInfo objectForKey:@"city"]); } //異步請求錯誤 - (void)requestFailed:(ASIHTTPRequest *)request { // NSError *error = [request error]; NSLog (@"Response JSON :%@", @"error"); }
https://github.com/jdg/MBProgressHUD 網絡
下載後導入MBProgressHUD.h MBProgressHUD.m 暫時沒有發現噁心的問題 異步
導入頭文件 MBProgressHUD.h,繼續2-3小試牛刀 ,2-3中咱們異步讀取天氣信息,因此咱們須要在請求前顯示加載動畫,在請求結束,或網絡出現問題時 咱們須要關閉動畫 ide
- (void)viewDidLoad { [super viewDidLoad]; //請求的後臺活動列表 NSURL *url = [NSURL URLWithString:@"http://m.weather.com.cn/data/101180701.html"]; ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url]; [request setDelegate:self]; [request startAsynchronous]; } //異步請求開始 - (void)requestStarted:(ASIHTTPRequest *)request { NSLog(@"request start :%@", @"start"); [MBProgressHUD showHUDAddedTo:self.view animated:YES]; } //異步請求結束 - (void)requestFinished:(ASIHTTPRequest *)request { [MBProgressHUD hideHUDForView:self.view animated:YES]; NSString *jsonString = [request responseString]; NSLog (@"Response JSON :%@", jsonString); SBJsonParser *parser =[[SBJsonParser alloc] init]; NSDictionary *rootDic = [parser objectWithString:jsonString]; NSDictionary *weatherInfo = [rootDic objectForKey:@"weatherinfo"]; NSLog (@"Response JSON city :%@", [weatherInfo objectForKey:@"city"]); } //異步請求錯誤 - (void)requestFailed:(ASIHTTPRequest *)request { // NSError *error = [request error]; NSLog (@"Response JSON :%@", @"error"); [MBProgressHUD hideHUDForView:self.view animated:YES]; }
https://github.com/enormego/EGOImageLoading
https://github.com/enormego/EGOTableViewPullRefresh
【5-2 注意事項】
須要在Link Binary with Libraries中加QuartzCore.framework Foundation.framework CoreGraphics.framework 以及 [1-2 中的注意事項]
ECSlidingViewController-master :https://github.com/edgecase/ECSlidingViewController