我是 java & php 程序员,遇到了坑爹的iPhone,被逼无奈在崩溃的边缘下学习object-c ,在学习中遇到了很多 奇葩,无知,龌蹉,呕吐的问题(弱弱的说 : 有的些问题到现在还不知道具体的原理)故此把开发中所有遇到的问题,和需要使用的开源库 一一记载下来,为那些苦B的要学习OBJECT-C的屌丝们加点料吧。本文纯粹记录性游记类文章,学术性观摩团请绕行,专家请绕行。在编写过程中避免不了出现问题或者遗漏问题,希望大家多多指点与板砖!
https://github.com/pokeb/asi-http-request
引入头文件 #import "ASIHTTPRequest.h"
更详细的使用方法请参照: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"); } //异步请求结束 - (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
解压后把相应的文件导入到工程中,尚未发现问题
在1-3的小试牛刀中,我们请求了有关天气的URL,这个URL会有一个JSON的相应,我们继续1-3,来解解析这个响应的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中我们异步读取天气信息,所以我们需要在请求前显示加载动画,在请求结束,或网络出现问题时 我们需要关闭动画
- (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