我目前正在我的網站上使用對我的API(I設置)的異步調用。我正在使用ASIHTTPRequest的setDownloadProgressDelegate和UIProgressView。然而,我不知道如何調用一個選擇器(updateProgress),它將設置一個CGFloat'進度'到progressView的進度。我嘗試了以下內容,但兩項進展均爲零。請你能告訴我怎樣才能使這個工作?如何使用ASIHTTPRequest(ASYNC)跟蹤下載進度
(in some method)
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:[url stringByAppendingFormat:@"confidential"]]];
[request setDownloadProgressDelegate:progressView];
[NSTimer scheduledTimerWithTimeInterval:1.0f/60.0f target:self selector:@selector(updateProgress:) userInfo:nil repeats:YES];
[request setCompletionBlock:^{~100 lines of code}];
[request setFailedBlock:^{~2 lines of code :) }];
[request startAsynchronous];
- (void) updateProgress:(NSTimer *)timer {
if (progressView.progress < 1.0) {
currentProgress = progressView.progress;
NSLog(@"currProg: %f --- progressViewProg: %f", currentProgress, progressView.progress);
}
else {
[timer invalidate];
}
return;
}
你能解釋一下你實際上試圖讓代碼做什麼 - 你想有一個進度視圖,也想知道你自己班級的進度嗎? – JosephH 2011-06-12 18:17:08
我希望能夠存儲一個名爲progress的CGFloat,當類中的方法被調用時它將被更新。它將在該方法中由ASIHTTPRequest進行更新。 – 2011-06-12 18:47:22