Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does UITableViewCell flash on changing height?

I have a simple UITableView with UITableViewCells. For the 0th row in the tableview, I have set a background color for the cell. Now on tapping the 0th row I just want the row to expand. In order to achieve this, I'm using the same technique as described here to change the 0th row height.

Now the problem is that the cell expands and collapses, but with each process there's an ugly flash/flicker on the cell. I've tried both beginupdates/endupdates and also reloading just that single row using [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath, nil] withRowAnimation:UITableViewRowAnimationNone];

What's causing the flicker/flash on tapping? And how do I get rid of it? And yes, I forgot to mention, I have set the cell's selection style to none. So that's not causing this.

like image 606
Bourne Avatar asked Feb 25 '14 07:02

Bourne


3 Answers

I had the same issue when using non-opaque background color of the cell. The solution is to use backgroundView property, instead of backgroundColor:

UIView *backgroundView = [[UIView alloc] initWithFrame:cell.frame];
backgroundView.backgroundColor = [[UIColor whiteColor] colorWithAlphaComponent:0.1f];
cell.backgroundView = backgroundView;
cell.backgroundColor = [UIColor clearColor];
like image 198
Karol Kulesza Avatar answered Oct 21 '22 23:10

Karol Kulesza


I've had a similar issue, with a few culprits:

  • Make sure all your tableview calls are on the main thread.
  • Check your cell height logic, if there are inconsistencies it could cause similar issues. Remember the cell heights need to be updated to the final heights before you ask the table to reload rows.
  • Use a solid cell background color. iOS 7 seems to have issues if the cell background color is not fully opaque. (I couldn't find a solution to this while while using a non-opaque bg color. I suspect it may be an iOS 7 bug.)
like image 36
psilencer Avatar answered Oct 22 '22 00:10

psilencer


If you don't want animation and stop the cell from flashing, you can use following solution -

     [UIView setAnimationsEnabled:NO];
     [self.tableView beginUpdates];

     [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath, nil]
                                               withRowAnimation:UITableViewRowAnimationNone];
     [self.tableView endUpdates];
     [UIView setAnimationsEnabled:YES];

The above snippet will have no animation on cells while reloading the cell

like image 23
Sandy Avatar answered Oct 22 '22 00:10

Sandy