前言1:IOS &IPhone 网络异步加载 asi-http-request【1-1 ASI HTTP 下载地址】【1-2 注意事项】【1-3 小试牛刀】 2:解析JSON数据 SBJSON【 2-1 SBJSON 下载地址】【2-2 注意事项】【2-3 小试牛刀】3:加载网络数据的时候 显示onLoading动画图片 MBProgressHUD【3-1 MBProgressHUD 下载地址】【3-2 注意事项】【3-3 小试牛刀】4:IOS &IPhone 异步图片加载 EGOImageLoadding【EGOImageLoadding 下载地址】 【小试牛刀】5:上拉刷新,下拉翻页【5-1 EGOTableViewPullRefresh 下载地址】6:左边菜单导航 前言
我是 java & php 程序员,遇到了坑爹的iPhone,被逼无奈在崩溃的边缘下学习object-c ,在学习中遇到了很多 奇葩,无知,龌蹉,呕吐的问题(弱弱的说 : 有的些问题到现在还不知道具体的原理)故此把开发中所有遇到的问题,和需要使用的开源库 一一记载下来,为那些苦B的要学习OBJECT-C的屌丝们加点料吧。本文纯粹记录性游记类文章,学术性观摩团请绕行,专家请绕行。在编写过程中避免不了出现问题或者遗漏问题,希望大家多多指点与板砖!
1:IOS &IPhone 网络异步加载 asi-http-request
【1-1 ASI HTTP 下载地址】
https://github.com/pokeb/asi-http-request
【1-2 注意事项】
- 下载asi-http-request-master后解压,把\Classes文件下所有文件,\External\Reachability 文件夹下所有文件添加到你的工程中。
- 在 Build Phases中添加相应的Link Binary With Libraries
1.MobileCoreServices.framework
2.SystemConfiguration.framework
3.CFNetwork.framework
4.Libz.dylib
- 由于ARC Restrictions导致的祖国山河一片红
选中相关文件 回车后输入命令:-fno-objc-arc
【1-3 小试牛刀】
引入头文件 #import "ASIHTTPRequest.h"
更详细的使用方法请参照:http://www.cnblogs.com/zhwl/archive/2012/07/14/2591752.html
01
- (
void
)viewDidLoad {
02
[super viewDidLoad];
03
04
NSURL *url = [NSURL URLWithString:@
"http://m.weather.com.cn/data/101180701.html"
];
05
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
06
[request setDelegate:self];
07
[request startAsynchronous];
08
09
}
10
11
12
- (
void
)requestStarted:(ASIHTTPRequest *)request {
13
NSLog(@
"request start :%@"
, @
"start"
);
14
}
15
16
- (
void
)requestFinished:(ASIHTTPRequest *)request {
17
18
NSString *jsonString = [request responseString];
19
NSLog (@
"Response JSON :%@"
, jsonString);
20
}
21
22
- (
void
)requestFailed:(ASIHTTPRequest *)request {
23
24
NSLog (@
"Response JSON :%@"
, @
"error"
);
25
}
2:解析JSON数据 SBJSON
【 2-1 SBJSON 下载地址】
https://github.com/stig/json-framework
【2-2 注意事项】
解压后把相应的文件导入到工程中,尚未发现问题
【2-3 小试牛刀】
在1-3的小试牛刀中,我们请求了有关天气的URL,这个URL会有一个JSON的相应,我们继续1-3,来解解析这个响应的JSON
01
- (
void
)viewDidLoad {
02
[super viewDidLoad];
03
04
05
06
NSURL *url = [NSURL URLWithString:@
"http://m.weather.com.cn/data/101180701.html"
];
07
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
08
[request setDelegate:self];
09
[request startAsynchronous];
10
11
}
12
13
14
- (
void
)requestStarted:(ASIHTTPRequest *)request {
15
NSLog(@
"request start :%@"
, @
"start"
);
16
}
17
18
- (
void
)requestFinished:(ASIHTTPRequest *)request {
19
NSString *jsonString = [request responseString];
20
NSLog (@
"Response JSON :%@"
, jsonString);
21
SBJsonParser *parser =[[SBJsonParser alloc] init];
22
NSDictionary *rootDic = [parser objectWithString:jsonString];
23
NSDictionary *weatherInfo = [rootDic objectForKey:@
"weatherinfo"
];
24
NSLog (@
"Response JSON city :%@"
, [weatherInfo objectForKey:@
"city"
]);
25
}
26
27
- (
void
)requestFailed:(ASIHTTPRequest *)request {
28
29
NSLog (@
"Response JSON :%@"
, @
"error"
);
30
}
3:加载网络数据的时候 显示onLoading动画图片 MBProgressHUD
【3-1 MBProgressHUD 下载地址】
https://github.com/jdg/MBProgressHUD
【3-2 注意事项】
下载后导入MBProgressHUD.h MBProgressHUD.m 暂时没有发现恶心的问题
【3-3 小试牛刀】
导入头文件 MBProgressHUD.h,继续2-3小试牛刀 ,2-3中我们异步读取天气信息,所以我们需要在请求前显示加载动画,在请求结束,或网络出现问题时 我们需要关闭动画
01
- (
void
)viewDidLoad {
02
[super viewDidLoad];
03
04
05
NSURL *url = [NSURL URLWithString:@
"http://m.weather.com.cn/data/101180701.html"
];
06
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
07
[request setDelegate:self];
08
[request startAsynchronous];
09
10
}
11
12
13
- (
void
)requestStarted:(ASIHTTPRequest *)request {
14
NSLog(@
"request start :%@"
, @
"start"
);
15
[MBProgressHUD showHUDAddedTo:self.view animated:YES];
16
}
17
18
- (
void
)requestFinished:(ASIHTTPRequest *)request {
19
[MBProgressHUD hideHUDForView:self.view animated:YES];
20
NSString *jsonString = [request responseString];
21
NSLog (@
"Response JSON :%@"
, jsonString);
22
SBJsonParser *parser =[[SBJsonParser alloc] init];
23
NSDictionary *rootDic = [parser objectWithString:jsonString];
24
NSDictionary *weatherInfo = [rootDic objectForKey:@
"weatherinfo"
];
25
NSLog (@
"Response JSON city :%@"
, [weatherInfo objectForKey:@
"city"
]);
26
}
27
28
- (
void
)requestFailed:(ASIHTTPRequest *)request {
29
30
NSLog (@
"Response JSON :%@"
, @
"error"
);
31
[MBProgressHUD hideHUDForView:self.view animated:YES];
32
}
4:IOS &IPhone 异步图片加载 EGOImageLoadding
【EGOImageLoadding 下载地址】
https://github.com/enormego/EGOImageLoading
【小试牛刀】
5:上拉刷新,下拉翻页
【5-1 EGOTableViewPullRefresh 下载地址】
https://github.com/enormego/EGOTableViewPullRefresh
【5-2 注意事项】
需要在Link Binary with Libraries中加QuartzCore.framework Foundation.framework CoreGraphics.framework 以及 [1-2 中的注意事项]
6:左边菜单导航
ECSlidingViewController-master :https://github.com/edgecase/ECSlidingViewController
文章转自http://my.oschina.net/superclass/blog/135195