Ios 使用自定义TableViewCell单击时,显示与TableView行对应的进度栏

Ios 使用自定义TableViewCell单击时,显示与TableView行对应的进度栏,ios,progress-bar,tableview,Ios,Progress Bar,Tableview,我为这个问题花了几个小时。我的tableview中有3行。 我还使用一个自定义单元格,其中包含一个按钮和一个进度条。 问题是,当我单击第一行或第二行的按钮时,progressbar总是显示在第三行。我不知道为什么。但我想显示与我们单击的行对应的progressbar @interface ViewController_ () { CustomViewCell *cell; } @end - (UITableViewCell *)tableView:(UITableVi

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

 @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;
}

你拿手机的方法不对。单元格实例将始终是表视图加载的最后一个单元格

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

您可以这样更改代码:

-(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;
}