【问题标题】:Progress bar in table cell表格单元格中的进度条
【发布时间】:2013-11-21 20:10:45
【问题描述】:

嗨,我的表格单元格显示有线响应..我有一个自定义表格表视图,每个单元格中有一个按钮和进度条..当我点击按钮时,一本书将下载,然后进度条将出现,直到这本书下载了,但是当我点击第二个单元格的按钮时,进度条出现在第二个单元格和第四个单元格中......我对此非常困惑,请提前帮助谢谢

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *simpleTableIdentifier = @"Categorycell";

    Categorycell *cell = (Categorycell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
    if (cell == nil)
    {
        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"Categorycell" owner:self options:nil];
        cell = [nib objectAtIndex:0];
    }
    [tableView setSeparatorColor:[UIColor clearColor]];
    cell.selectionStyle=UITableViewCellSelectionStyleNone;
cell.cell_btn.tag       = indexPath.row*10+1;

    [cell.cell_btn addTarget:self action:@selector(btnDown:) forControlEvents:UIControlEventTouchUpInside];

    cell.cell_ReadBtn.tag       =indexPath.row*10+1;
    [cell.cell_ReadBtn addTarget:self action:@selector(btnRead:) forControlEvents:UIControlEventTouchUpInside];

    cell.cell_Progress.tag= indexPath.row*10+1;

    if(!bIspress)
    {
    cell.cell_Progress.hidden=YES;
    }
    NSString *comicbook_id = [arr_comic_id objectAtIndex:indexPath.row];
    NSString  *filePath = [NSString stringWithFormat:@"book_%@.pdf",comicbook_id];
    NSLog(@"Book Name : %@",filePath);
    if(![appDelegate check_Book_available:filePath])
    {
        NSLog(@"Book Name Not : %@",filePath);
    cell.cell_ReadBtn.hidden=YES;
        cell.cell_btn.hidden= NO;
    }
    else
    {
        cell.cell_btn.hidden=YES;
        cell.cell_ReadBtn.hidden=NO;

    }
    cell.tag=indexPath.row*10+1;
    return cell;
}



-(void)btnDown:(UIButton*)sender
{
    NSLog(@"Called when press");


   // sender.hidden = YES;
    dlIndex = sender.tag/10;
    bIspress=true;
    NSLog(@"INDEX : %d : %d",dlIndex,[sender tag]);
// Categorycell *cell = (Categorycell *)[self.tbl_view dequeueReusableCellWithIdentifier:@"Categorycell"];
//    cell.cell_Progress.hidden=NO;
//    [cell.cell_Progress setProgress:0.];
    NSString *str_id=[arr_comic_id objectAtIndex:dlIndex];
    [[NSUserDefaults standardUserDefaults] setValue:str_id forKey:@"book_id"];
   //     dlIndex = [sender tag]/10;
    dlCell = (Categorycell *)[[sender superview]superview];
    NSLog(@"INDEX progress : %d : Cell Tag : %d",dlCell.cell_Progress.tag,dlCell.tag);

     NSIndexPath *path = [tbl_view indexPathForCell:dlCell];
    if(dlCell.cell_Progress.tag==dlCell.cell_btn.tag)
    {

         [self Apicall_background];

    }

//    cell_Progressview = (UIProgressView* )[dlCell.contentView viewWithTag:dlIndex*10+1];
//    cell_Progressview.hidden = NO;




}

【问题讨论】:

    标签: ios uitableview


    【解决方案1】:

    试试这个

    -(void)btnDown:(UIButton*)sender
    {
    
         //your code
    
         if(dlCell.cell_Progress.tag==dlCell.cell_btn.tag)
         {
    
              [self Apicall_background];
              CGPoint center = CGPointMake(CGRectGetMidX(dlCell.bounds),
                                           CGRectGetMidY(dlCell.bounds));
    
    
              dlCell.cell_Progress.center = center;
    
         }
    }
    

    【讨论】:

    • 当我点击表格单元格的按钮进度条时,我没有询问我需要的位置
    【解决方案2】:

    糟糕的解决方案,但这应该可以解决您的问题。

    Categorycell *cell = (Categorycell *)[tableView dequeueReusableCellWithIdentifier:nil];
    

    【讨论】:

    • 当我点击表格单元格的按钮进度条时,我不是在询问我需要的位置,请帮助我
    • 你试过了吗?您说您的进度条出现在正确的单元格中,并且出现在另一个单元格中。所以这是一个快速修复。
    • [tableView dequeueReusableCellWithIdentifier:nil];如果我把 nil 放在标识符上意味着它如何在你告诉更新的地方进入 tableview 请告诉
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-07
    • 2012-11-25
    • 1970-01-01
    • 2018-03-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多