0

I have a UITableViewCell. I'm trying to animate a progress bar when the cell comes into view. I have tried the following but it does nothing.

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

    TableViewCellResults *cell = [tableView dequeueReusableCellWithIdentifier:cellId];

    if (cell == nil) {
        cell = [[TableViewCellResults alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellId];
    }

    // Add progress bar here

    // THIS DOES NOTHING
    [UIView animateWithDuration:10.f animations:^{
        progressBar.value = 55.f;
    }];

How do I animate the UIProgressBar? The UIProgressBar does not accept 'animateWithDuration'.

I have working sample of animating the UIProgressBar in UIView (not a cell) that uses the same syntax.

Gaurav Patel
  • 532
  • 1
  • 5
  • 19
Jon
  • 1,608
  • 7
  • 25
  • 38
  • Is the progress bar contained within the cell? – kevin May 11 '18 at 02:40
  • You've left out the important code. Show your complete `cellForRowAtIndexPath` method. – rmaddy May 11 '18 at 03:25
  • 1
    Try putting animation code in `- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath;` or `- (void)tableView:(UITableView *)tableView didEndDisplayingCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath*)indexPath` – Sandy May 11 '18 at 03:31
  • Yes.. progress bar in cell. – Jon May 11 '18 at 10:54
  • Can't paste the full cellForRowAt - too many chars – Jon May 11 '18 at 10:55
  • I have tried adding this: - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath { [UIView animateWithDuration:10.f animations:^{ self.progressBar.value = 55.f; }]; } – Jon May 11 '18 at 10:56
  • But does not animate.. does get fired – Jon May 11 '18 at 10:56
  • Is UIView correct for willDisplayCell? tableView does not have animateWithDuration – Jon May 11 '18 at 17:12

1 Answers1

0

Try perform animations using UIView.commmitAnimations() eg:

 UIView.beginAnimations(“rotation”, context: nil)

    UIView.setAnimationDuration(0.8)

    cell.layer.transform = CATransform3DIdentity

    cell.alpha = 1

    cell.layer.shadowOffset = CGSize(width: CGFloat(0), height: CGFloat(0))

    UIView.commitAnimations()

also try to perform the operation inside willDisplayCell: Method.

Refer this http://www.thinkandbuild.it/animating-uitableview-cells/ solution to perform animations inside tableview cell

Tibin Thomas
  • 1,365
  • 2
  • 16
  • 25