ios - 使用自定义 UITableViewCell 单击时显示与 TableView 行对应的进度条

标签 ios progress-bar tableview

我在这个问题上停留了几个小时。我的 TableView 中有 3 行。 我还使用包含 1 个按钮和 1 个进度条的自定义单元格。 问题是当我点击第一行或第二行的按钮时,进度条总是显示在第三行。我不知道为什么。但我想显示与我们单击的行对应的进度条。

 @interface ViewController_ ()
 {

     CustomViewCell  *cell;

 }

@end


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

    static NSString *CellIdentifier = @"Cell";
    cell = (CustomViewCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell==nil) {
       NSArray *nib;
       nib = [[NSBundle mainBundle] loadNibNamed:@"IssueViewCell" owner:self options:nil];
       for (id oneObject in nib)
          if ([oneObject isKindOfClass:[CustomViewCell class]])
                cell = (CustomViewCell *)oneObject;
    }

    cell.progressBar.hidden = YES;
    [cell.downloadButton setTitle:@"Download" forState:UIControlStateNormal];
    [cell.downloadButton addTarget:self action:@selector(downloadButtonCliked:) forControlEvents:UIControlEventTouchUpInside];

}

-(void) downloadButtonCliked:(UIButton *)sender{

      NSLog(@"Called when press");
      cell.progressBar.hidden = NO;
}

最佳答案

您没有以正确的方式获取单元格。您的单元格实例将始终是表格 View 加载的最后一个单元格。

您应该删除单元格引用,您不需要它。

您可以像这样更改代码:

-(void) downloadButtonCliked:(UIButton *)sender{
      NSLog(@"Called when press");
      CustomViewCell *buttonCell = (CustomViewCell*) sender.superview.superview;
      //if you add the button to the cell view the you should call sender.superview;
      buttonCell.progressBar.hidden = NO;
}

关于ios - 使用自定义 UITableViewCell 单击时显示与 TableView 行对应的进度条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16560273/

相关文章:

c# - 带有文本的 WPF DataGrid 进度条

android - 如何在android中获取带有文本的水平进度条

ios - JSON Swift 填充 TableView 错误

JavaFX - 将列 id/order 放入列表/数组中

ios - Xcode - 我更改了产品模块名称,现在自动完成功能将不再起作用(使用新模块名称时)

android - 没有 Firebase 的 flutter 中的 OTP 验证

iphone - 我在哪里可以获得有关 VOIP 应用程序的 iOS 文件处理程序的信息?

r - 使用 doParallel + foreach 显示 progress_bar

objective-c - 使用 UIImagePickerController 录制视频并达到 videoMaximumDuration 时更改 UIAlertView 的文本

ios - swift 2.0 : How to disable current user from pressing button again?