匯總iOS開發(fā)中需要用到的開源庫
我是 java & php 程序員,遇到了坑爹的iPhone,被逼無奈在崩潰的邊緣下學(xué)習(xí)Object-C ,在學(xué)習(xí)中遇到了很多 奇葩,無知,齷蹉,嘔吐的問題(弱弱的說 : 有的些問題到現(xiàn)在還不知道具體的原理)故此把開發(fā)中所有遇到的問題,和需要使用的開源庫 一一記載下來,為那些苦B的要學(xué)習(xí)Object-C的屌絲們加點料吧。本文純粹記錄性游記類文章,學(xué)術(shù)性觀摩團(tuán)請繞行,專家請繞行。在編寫過程中避免不了 出現(xiàn)問題或者遺漏問題,希望大家多多指點與板磚!
1、iOS &iPhone 網(wǎng)絡(luò)異步加載 asi-http-request
【1-1 ASI HTTP 下載地址】
https://github.com/pokeb/asi-http-request
【1-2 注意事項】
下載asi-http-request-master后解壓,把\Classes文件下所有文件,\External\Reachabipty 文件夾下所有文件添加到你的工程中。
在 Build Phases中添加相應(yīng)的pnk Binary With pbraries
(1)MobileCoreServices.framework
(2)SystemConfiguration.framework
(3)CFNetwork.framework
(4)pbz.dypb
由于ARC Restrictions導(dǎo)致的祖國山河一片紅
選中相關(guān)文件 回車后輸入命令:-fno-objc-arc
【1-3 小試牛刀】
引入頭文件 #import "ASIHTTPRequest.h"
更詳細(xì)的使用方法請參照:http://www.cnblogs.com/zhwl/archive/2012/07/14/2591752.html
- (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");
}
//異步請求結(jié)束
- (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");
}
2、解析JSON數(shù)據(jù) SBJSON
【 2-1 SBJSON 下載地址】
https://github.com/stig/json-framework
【2-2 注意事項】
解壓后把相應(yīng)的文件導(dǎo)入到工程中,尚未發(fā)現(xiàn)問題
【2-3 小試牛刀】
在1-3的小試牛刀中,我們請求了有關(guān)天氣的URL,這個URL會有一個JSON的相應(yīng),我們繼續(xù)1-3,來解解析這個響應(yīng)的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");
}
//異步請求結(jié)束
- (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");
}
3、加載網(wǎng)絡(luò)數(shù)據(jù)的時候 顯示onLoading動畫圖片 MBProgressHUD
【3-1 MBProgressHUD 下載地址】
https://github.com/jdg/MBProgressHUD
【3-2 注意事項】
下載后導(dǎo)入MBProgressHUD.h MBProgressHUD.m 暫時沒有發(fā)現(xiàn)惡心的問題
【3-3 小試牛刀】
導(dǎo)入頭文件 MBProgressHUD.h,繼續(xù)2-3小試牛刀 ,2-3中我們異步讀取天氣信息,所以我們需要在請求前顯示加載動畫,在請求結(jié)束,或網(wǎng)絡(luò)出現(xiàn)問題時 我們需要關(guān)閉動畫
- (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];
}
//異步請求結(jié)束
- (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];
}
4、iOS &IPhone 異步圖片加載 EGOImageLoadding
【EGOImageLoadding 下載地址】
https://github.com/enormego/EGOImageLoading
【小試牛刀】
5、上拉刷新,下拉翻頁
【5-1 EGOTableViewPullRefresh 下載地址】
https://github.com/enormego/EGOTableViewPullRefresh
【5-2 注意事項】
需要在pnk Binary with pbraries中加QuartzCore.framework Foundation.framework CoreGraphics.framework 以及 [1-2 中的注意事項]
6、左邊菜單導(dǎo)航 ECSpdingViewController-master :