小编use*_*376的帖子

自定义UITableViewCell与进度条下载更新

我正在尝试使用进度条加载更新每个表格单元格,但我被卡住了.我为具有以下属性的表视图创建了一个自定义单元格:

@interface OFPTableCell : UITableViewCell 
@property (nonatomic, weak) IBOutlet UILabel *textLabel;
@property (nonatomic, weak) IBOutlet UILabel *detailTextLabel;
@property (weak, nonatomic) IBOutlet UIImageView *imageView;
@property (weak, nonatomic) IBOutlet UIProgressView *progressView;
@end;
Run Code Online (Sandbox Code Playgroud)

在@synthesize它们之后,现在我在每个表格单元格中都有预期的进度条.

问题是,当我尝试使用加载进度条更新甚至第一个单元格时,它只是不执行任何操作或设置为0或完整进度条.请注意,下载过程正常.

您可以找到我尝试更新进度条的代码:

 - (void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask          *)downloadTask didWriteData:(int64_t)bytesWritten
  totalBytesWritten:(int64_t)totalBytesWritten totalBytesExpectedToWrite:    (int64_t)totalBytesExpectedToWrite
{

      dispatch_async(dispatch_get_main_queue(), ^{
      NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
      OFPTableCell *cell = (OFPTableCell*)[self tableView:self.tableViewCache    cellForRowAtIndexPath:indexPath];
      cell.progressView.progress=(double)totalBytesWritten /  (double)totalBytesExpectedToWrite;
});

}
Run Code Online (Sandbox Code Playgroud)

下面是方法cellForRowAtIndexPath:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

     OFPTableCell *cell = [self.tableViewCache dequeueReusableCellWithIdentifier:@"Cell"];



    OFPVideoDetails *vd = [someArray objectAtIndex:indexPath.row]; …
Run Code Online (Sandbox Code Playgroud)

objective-c uitableview ios

6
推荐指数
1
解决办法
9744
查看次数

标签 统计

ios ×1

objective-c ×1

uitableview ×1