Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Only animate cell from willDisplayCell when user scroll, not after reloadData

Ok so I have a custom animation being implemented inside willDisplayCell method. It is working fine when I scroll the view up and down. When I tap on one of the row, it will be pushed to another view controller to show more details and let user update the data.

The issue is when the user get back to the tableview. I called the [tableView reloadData] method inside the viewWillAppear to make sure updated data is shown. This will trigger the animation transition that I set up earlier.

My question is: Is there a way to only perform the animation when user scroll up/down the tableview, not when the reloadData is called?

If there's a way to mix between the willDisplayCell with scrollViewDidScroll or something along that line, it would be awesome.

Thanks!

like image 454
Gaddafi Rusli Avatar asked Oct 20 '22 15:10

Gaddafi Rusli


1 Answers

The easiest solution would be to add a state flag that would tell the willDisplayCell whether it should actually animate.

Add a property to your UITableViewDelegate:

@property (nonatomic) BOOL shouldPreventDisplayCellAnimation;

Set the property before and after calling reloadData:

- (void)viewWillAppear:(BOOL)animated
{
  …
  self.shouldPreventDisplayCellAnimation = YES;
  [self.tableView reloadData];
  self.shouldPreventDisplayCellAnimation = NO:
}

Modify willDisplayCell to animate on condition

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
  if (!self.shouldPreventDisplayCellAnimation) {
    //animate
  }
}
like image 127
Bartosz Ciechanowski Avatar answered Oct 27 '22 19:10

Bartosz Ciechanowski