【发布时间】:2013-01-26 22:22:58
【问题描述】:
我快疯了,当我下载文件时,我正在尝试更新UICollectionViewCelll 的progressBar,我已经尝试了一切,一切都尝试了,这是我最后一次尝试,我创建了@987654322 的子类@,与xib 文件相连:
#import <UIKit/UIKit.h>
@interface DocumentCell : UICollectionViewCell
@property (weak, nonatomic) IBOutlet UIImageView *documentImage;
@property (weak, nonatomic) IBOutlet UIProgressView *downloadBar;
- (void)downloadDocumentWithUrl:(NSURLRequest *)requestUrl;
@end
- (void)downloadDocumentWithUrl:(NSURLRequest *)requestUrl
{
.....
AFDownloadRequestOperation *request = [[AFDownloadRequestOperation alloc] initWithRequest:requestUrl targetPath:zipDownloadPath shouldResume:YES];
[request setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"Successfully downloaded file to %@", zipDownloadPath);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
}];
[request setProgressiveDownloadProgressBlock:^(NSInteger bytesRead, long long totalBytesRead, long long totalBytesExpected, long long totalBytesReadForFile, long long totalBytesExpectedToReadForFile) {
NSLog(@"%f",totalBytesReadForFile/(float)totalBytesExpectedToReadForFile);
[self performSelectorOnMainThread:@selector(updateBar:) withObject:[NSNumber numberWithFloat:(totalBytesReadForFile/(float)totalBytesExpectedToReadForFile)] waitUntilDone:YES];
}];
[downloadQueue addOperation:request];
}
- (void)updateBar:(NSNumber *)floatNumber
{
[self.downloadBar setProgress:[floatNumber floatValue]];
}
NSLog setProgressiveDownloadProgressBlock 完美运行,我可以看到我下载的所有字节,但progressBar 不会自行更新,始终保持为零...我不明白怎么做...这就是我的方式显示单元格,调用方法下载:
- (void)startDownload:(NSString *)downloadUrl
{
//DocumentCell *cell = (DocumentCell *)[self.collectionView cellForItemAtIndexPath:self.downloadPath]; i have tried also in this way
DocumentCell *cell = (DocumentCell *)[self.collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:self.downloadPath];
[cell downloadDocumentWithUrl:requestUrl];
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
UINib *cellNib = [UINib nibWithNibName:@"DocumentCell" bundle:nil];
[self.collectionView registerNib:cellNib forCellWithReuseIdentifier:CellIdentifier];
...
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
DocumentCell *cell = (DocumentCell *)[collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];
cell.documentImage.....etc
return cell;
}
有人可以帮助我吗?调用下载文件的方法,下载的字节的nslog有效,进度条不...请帮我更新这个进度条...
【问题讨论】:
-
t 值它返回 totalBytesReadForFile/(float)totalBytesExpectedToReadForFile)
标签: iphone ios uicollectionview uicollectionviewcell uiprogressbar