使用 ASIHTTPRequest 跟踪进度
我正在尝试与网络服务进行通信并检索数据,同时,我尝试使用 UIProgressView 进行进度指示,以便用户知道发生了什么,但是,当我运行时,我看不到进度UIProgressView。 这是我的相关代码:
- (void)viewDidLoad {
[super viewDidLoad];
//start request
NSURL *url=[NSURL URLWithString:@"http://iphone01.mtdgroup/admin_V01/stationsProcessing/pickers_management.php"];
ASIFormDataRequest *request=[ASIFormDataRequest requestWithURL:url];
[request setDelegate:self];
[request setUploadProgressDelegate:loadingProgress];
[request startAsynchronous];
NSLog(@"value: %f",[loadingProgress progress]);
}
日志显示:值:0.000000
。 根据 ASIHTTPRequest 文档,将 UIProgressView
设置为 uploadProgressDelegate
的委托就足够了,ASIHTTPRequest 将负责为我更新 UIProgressView。 我错过了什么吗?谢谢提前:)
i am trying to communicate to web-service and to retrieve data, while doing that, i try to make progress indication with UIProgressView so that the user know what's going on, however, when i run, i don't see the progress on the UIProgressView.
here is my relevant code :
- (void)viewDidLoad {
[super viewDidLoad];
//start request
NSURL *url=[NSURL URLWithString:@"http://iphone01.mtdgroup/admin_V01/stationsProcessing/pickers_management.php"];
ASIFormDataRequest *request=[ASIFormDataRequest requestWithURL:url];
[request setDelegate:self];
[request setUploadProgressDelegate:loadingProgress];
[request startAsynchronous];
NSLog(@"value: %f",[loadingProgress progress]);
}
the log shows : value: 0.000000
.
According to the ASIHTTPRequest documentation, setting the UIProgressView
as the delegate of the uploadProgressDelegate
is sufficient and ASIHTTPRequest will take care of updating the UIProgressView for me.
am i missing something ? thx for advance :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您正在执行异步请求,因此 NSLog 在请求开始后立即执行,此时进度实际上为零 - startAsynchronous 实际上在幕后使用 NSOperationQueue,因此如果您想要 NSLog,则需要编写自己的委托进度:
只需在视图控制器中包含类似的内容:
并设置:
You're doing an Asynchronous request so the NSLog executes immediately after the request is started at which point the progress would actually be zero - startAsynchronous actually uses an NSOperationQueue behind the scenes so you'll need to code your own delegate if you want to NSLog the progress:
just include something like this in your view controller:
and set:
确保您的类也符合
ASIProgressDelegate
协议。Make sure your class also conforms to the
ASIProgressDelegate
protocol.