简体   繁体   中英

How to add UIProgressView in UITableView in iOS

I am using custom UIProgressView in UITableView this work properly but not particular index ..like my table show 3 cells then when we select first cell or index then my progress view show on 3rd index and when we scroll my table then progress view show on each cell of table ....so I want selected index show progress view .

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
  {
//static NSString *MyCellIdentifier = @"MyIdentifier";
 NSString *MyCellIdentifier = [NSString stringWithFormat:@"S%1dR%1d",indexPath.section,indexPath.row];
 UITableViewCell *cell1 = [tableView dequeueReusableCellWithIdentifier:MyCellIdentifier];
    if(cell1==nil)
    {
        cell1=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:MyCellIdentifier];

    }

 UIProgressView *prg =[[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleDefault];
 CGAffineTransform transform = CGAffineTransformMakeScale(1.0f, 5.0f);
 prg.transform = transform;
 prg.progressTintColor=[UIColor blueColor];
 [cell1.contentView addSubview:prg];

cell1.textLabel.text = [NSString stringWithFormat: @"%@",[[item objectAtIndex:indexPath.row-1]objectForKey:@"MusicName"]];
cell1.textLabel.textColor = [UIColor redColor] ;

    return cell1;

}

use this ....

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{

    [prg removeFromSuperview];

    UITableViewCell *cell = (UITableViewCell *)[tableView cellForRowAtIndexPath:indexPath];
    prg =[[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleDefault];
    CGAffineTransform transform = CGAffineTransformMakeScale(1.0f, 5.0f);
    prg.transform = transform;
    prg.progressTintColor=[UIColor blueColor];
    [cell addSubview:prg];
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM