私はアップロードを保持するNSObjectを持っています。プロパティの1つはfileProgress(float)です。更新cellForRowAtIndexPath progressView
NSURLSessionDelegateMethod
URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didSendBodyData:(int64_t)bytesSent totalBytesSent:(int64_t)totalBytesSent totalBytesExpectedToSend:(int64_t)totalBytesExpectedToSend
という名前で進行状況が更新されます。
アップロードオブジェクトは、taskIdentifier
を使用して正しく更新されます。
別のクラスでは、progressView
のカスタムUITableViewCellを持つUITableViewがあります。 progressView
を現在のfileProgressに更新したいと思います。
アップロードがNSObjectクラスで完了すると、アップロードが削除され、デリゲートメソッドが呼び出され、デリゲートがキューカウントの変更があったことを知らせます。アップロードの進捗状況の表示がその瞬間に変更されるため、
を更新するには、現在のセルの進行状況を参照するにはどうすればよいですか?
私はcellForRowAtIndexPath
に追加しようとしましたが、それはうまくいかないようです。
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
cell.progressView.progress = item.fileProgress;
cell.lblProgress.text = [NSString stringWithFormat:@"%.1f%%", (item.fileProgress * 100) ];
}];
私はちょっとここでは失われています。どんな助け?
アップロード項目
@interface AMUploadItem : NSObject <NSCoding>
@property float fileProgress; //The fractional progress of the uploaded; a float between 0.0 and 1.0.
@property (nonatomic, strong) NSURLSessionUploadTask *uploadTask; //A NSURLSessionUploadTask object that will be used to keep a strong reference to the upload task of a file.
@property (nonatomic) unsigned long taskIdentifier;
@end
カスタムTableViewCell.h(空.M)
@interface ItemTableViewCell : UITableViewCell
@property (weak, nonatomic) IBOutlet UILabel *lblProgress;
@property (weak, nonatomic) IBOutlet UIProgressView *progressView;
@end
表ビューコントローラ
- (void)viewDidLoad {
[super viewDidLoad];
_manager = [AMPhotoManager sharedManager];
_manager.delegate = self;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [_manager getQueueCount];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *simpleTableIdentifier = @"cellUpload";
ItemTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil) {
cell = [[ItemTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}
AMUploadItem * item = [_manager listImagesInQueue][indexPath.row];
//THIS DOENS'T WORK
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
cell.progressView.progress = item.fileProgress;
cell.lblProgress.text = [NSString stringWithFormat:@"%.1f%%", (item.fileProgress * 100) ];
}];
return cell;
}
マネージャクラスには、AMItemUploadsとNSURLSessionUploadTask
ディレガの配列が格納されています。