私は夢中になってUICollectionViewCelll
います、私はファイルをダウンロードするときに a のプログレスバーを更新しようとしています、私はすべてを試しました、すべてすべて、これが私の最後の試みです、私はファイルUICollectionViewCell
に接続された のサブクラスを作成しました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 が機能し、進行状況バーが表示されません...この進行状況バーを更新するのを手伝ってください...