我有一個保存上傳的NSObject。其中一個屬性是fileProgress(float)。更新cellForRowAtIndexPath progressView
進度通過名爲 URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didSendBodyData:(int64_t)bytesSent totalBytesSent:(int64_t)totalBytesSent totalBytesExpectedToSend:(int64_t)totalBytesExpectedToSend
的NSURLSessionDelegateMethod
更新。
上傳對象使用taskIdentifier
正確更新。
在一個不同的類,我有一個UITableView與自定義的UITableViewCell有progressView
。我想用當前的fileProgress更新progressView
。
當上傳在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
delegaes的數組。