我正在使用此代碼將圖像設置爲UIImageView。AFNetworking setImageWithURLRequest下載進度
NSURLRequest *URLRequest = [[NSURLRequest alloc] initWithURL:[NSURL URLWithString:imageToLoad]];
[imageView setImageWithURLRequest:URLRequest placeholderImage:nil success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image) {
[cell.image setImage:image];
[cell.activityIndicator stopAnimating];
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error) {
// Nothing
}];
但我想跟蹤與方法下載進度,是possbile做到在setImageWithURLRequest方法?
通常我這樣做是爲了顯示加載進度百分比:
[SVProgressHUD showWithStatus:@"Start download..."];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:link]];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
// success
[SVProgressHUD showSuccessWithStatus:@"Done."];
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
// failed
[SVProgressHUD showErrorWithStatus:@"Failed."];
}];
[operation setDownloadProgressBlock:^(NSUInteger bytesRead, long long totalBytesRead, long long totalBytesExpectedToRead) {
[SVProgressHUD showWithStatus:[NSString stringWithFormat:@"Downloading... %0.0f%%", totalBytesRead*100*1.0/(totalBytesRead+totalBytesExpectedToRead)]];
}];
我已經回答了這個問題在[http://stackoverflow.com/questions/34744024/afnetworking-3-0-setimagewithurlrequest-download-progress/36983966#36983966](http://stackoverflow.com/questions/34744024/afnetworking-3-0-setimagewithurlrequest-download-progress/36983966#36983966) – Jegan