使用 ASIHTTPRequest 跟踪进度

发布于 2024-11-06 06:55:20 字数 761 浏览 1 评论 0原文

我正在尝试与网络服务进行通信并检索数据,同时,我尝试使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

黒涩兲箜 2024-11-13 06:55:20

您正在执行异步请求,因此 NSLog 在请求开始后立即执行,此时进度实际上为零 - startAsynchronous 实际上在幕后使用 NSOperationQueue,因此如果您想要 NSLog,则需要编写自己的委托进度:

只需在视图控制器中包含类似的内容:

- (void)setProgress:(float)newProgress {
   [loadingProgress setProgress:newProgress];
   NSLog(@"value: %f",[loadingProgress progress]);
}

并设置:

[request setUploadProgressDelegate:self];

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:

- (void)setProgress:(float)newProgress {
   [loadingProgress setProgress:newProgress];
   NSLog(@"value: %f",[loadingProgress progress]);
}

and set:

[request setUploadProgressDelegate:self];
无声情话 2024-11-13 06:55:20

确保您的类也符合 ASIProgressDelegate 协议。

@interface YourClass : ... <ASIHTTPRequestDelegate,ASIProgressDelegate>

Make sure your class also conforms to the ASIProgressDelegate protocol.

@interface YourClass : ... <ASIHTTPRequestDelegate,ASIProgressDelegate>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文