Rahul Sharma
Rahul Sharma

Reputation: 950

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;

}

Upvotes: 2

Views: 1409

Answers (1)

Rahul Sharma
Rahul Sharma

Reputation: 950

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

Upvotes: 4

Related Questions