How to animate a UIProgressView on each cell in a UITableView at the same time?

410 views Asked by At

I have a custom cell for a UITableView. The custom cell has a UIProgressView. I would like to set the progress for each cell's progressView with animation at the same time for all cells. The animation should start at viewDidAppear.

1

There are 1 answers

0
Henrique Barros On

You can use NSTimer to control the animation and create a global progressView to control the cells' progressView. So:

UIProgressView *progressGlobal;

- (void)viewDidAppear:(BOOL)animated
{
    NSTimer *timer = [NSTimer timerWithTimeInterval:1 target:self selector:@selector(increaseProgress) userInfo:nil repeats:YES];

    [timer fire];
}
- (void)increaseProgress
{
    [progressGlobal setProgress:(progressGlobal.progress + 5) animated:YES];
    [[self tableView] reloadData];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *voCell = [tableView dequeueReusableCellWithIdentifier:TABLE_VIEW_CELL_IDENTIFIER forIndexPath:indexPath];
    UIProgressView *localProgress = (UIProgressView *)[voCell viewWithTag:25];
    [localProgress setProgress:progressGlobal.progress animated:YES];
}