background image

iOS 网络编程-ASIHTTPRequest 小例子-数据请求队列

    我们通过一个例子介绍一下请求队列使用,我们设计了一个应用,用户点击 GO 按钮从
服务器同时下载两张图片显示在画面中。

 

    我们直接看看主视图控制器 ViewController.h 代码如下:

#import “ASIHTTPRequest.h”

#import “ASINetworkQueue.h”

#import “NSNumber+Message.h”

#import “NSString+URLEncoding.h”

 

@interface ViewController : UIViewController

 

@property (weak, nonatomic) IBOutlet UIImageView *imageView1;

@property (weak, nonatomic) IBOutlet UIImageView *imageView2;

@property (strong) ASINetworkQueue  *networkQueue;

 

- (IBAction)onClick:(id)sender;

@end

    我们需要引入 ASI 框架的两个头文件 ASIHTTPRequest.h 和 ASINetworkQueue.h。其中
imageView1 和 imageView2 是与画面对应的两个图片视图控件。还定义了 ASINetworkQueue 
类型的

networkQueue 属性。我们直接看看主视图控制器 ViewController.m 中点击 GO 按钮调

用方法,代码如下:

- (IBAction)onClick:(id)sender {

if (!_networkQueue) {