2

In my view controller I have a table view as a subview. When the keyboard disappears, I'm using self.view.layoutIfNeeded() to animate the table view. This goes all well except for the table view cells.

The cells consists of a few labels, set up with auto layout. When the keyboard disappears, layoutIfNeeded is called for the table view but is affecting the cells as well. This results in weird behavior of the cells, having the labels "fly" to their position.

Is there a way to isolate layoutIfNeeded to the table view only without affecting it's subviews?

Hendrik Smoels
  • 240
  • 3
  • 12

1 Answers1

4

This works for me:

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    [UIView performWithoutAnimation:^{
        [cell layoutIfNeeded];
    }];
}

Source: https://stackoverflow.com/a/26454792/1925852

Community
  • 1
  • 1
Thiêm
  • 155
  • 8