Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stop UITableViewCells from animating when animating a UITableView

I am animating a UITableView. I want the table view to slide open like this:

http://www.youtube.com/watch?v=XIGJLbiRsXE

However, it opens like this:

http://www.youtube.com/watch?v=UJUX-ILCB_0

Notice how the table cells themselves are animating. How can I stop this from happening?

I am using autolayout. The code is thus:

[theView addSubview:theTable];
[theTable reloadData];
[theTable invalidateIntrinsicContentSize];
[UIView animateWithDuration:.33 animations:^{
    [theView layoutIfNeeded];
 }];

Other details, which may or may not matter:

  • The table view's parent is a scrollView

  • I have overridden the intrinsicContentSize of the table view to return the height of all the cells in the table view, so the table view will not scroll

  • I am changing the datasource of the table view before displaying it

like image 385
dragosaur Avatar asked Apr 29 '13 17:04

dragosaur


1 Answers

I had a similar problem and was able to stop the animation on the UITableViewCell with the UIView performWithoutAnimation: method.

Use the tableView:willDisplayCell:forRowAtIndexPath: UITableViewDelegate method to get a reference to the cell before it is shown. Then, within the performWithoutAnimation: block, call layoutIfNeeded on the cell object to give it a chance to layout its subviews:

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    [UIView performWithoutAnimation:^{
        [cell layoutIfNeeded];
    }];
}
like image 129
Brian Watkins Avatar answered Sep 24 '22 14:09

Brian Watkins