Vignesh Vignesh - 1 year ago 118
iOS Question

iOS - TableView willDisplayCell animation only happen when user scrolling down not to the top

Hi am going to animate the table view cell when the user scrolling down if the user scroll to the top the will normally move with out animation.

-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cells forRowAtIndexPath:(NSIndexPath *)indexPath{
cells.alpha = 0.0;
[UIView animateWithDuration:0.4 animations:^{
cells.alpha = 1.0;

i tried like this but the animation happen all the time

Answer Source

Create a Custom cell with Bool Property "isAnimated". By Default "isAnimated" value is "NO".

and do code changes in willDisplayCell:(UITableViewCell *)cell method.

-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
//Typecast UITableViewCell to CustomCell. ex: CustomCell *objCell = (CustomCell *)cell
// check isAnimated or not 
   if(cell.isAnimated) return;
   cell.alpha = 0.0;
   [UIView animateWithDuration:0.4 animations:^{
      cell.alpha = 1.0;
      cell.isAnimated = YES;

Here Cell reference is Custom Cell reference. I hope this code works for you

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download