Custom TableViewCells are flickering while reloading tableview

215 views Asked by At

downloaded sample chat demo app from net. I have to change the layout direction of two custom cells (incoming messages left side, outgoing messages right side). Both incoming and outgoing cells layout direction are left as of now. So, I changed outgoing cells direction as right with UISemanticContentAttributeForceRightToLeft.

It is working fine with incoming messages left side, outgoing messages right side. But custom tableview cells are flickering while reloading tableview.

Please help me with this without changing the design of outgoing message cells.

1

There are 1 answers

5
Andreas Oetjen On

You should remove the dispatch_async stuff from cellForrowAtIndexPath.

That function is already running in the UI thread, so there is no need to dispatch anything into the main queue.

Also, since cells are being reused, you should also set the semanticContentAttribute to left-to-right when indexPath.row%2 != 0, because otherwise you'll end up in only right-to-left cells after scrolling a while:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *cellIdentifier = @"MovieCell";
    MoviesTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];
    if (indexPath.row%2 == 0) {
        cell.contentView.semanticContentAttribute = UISemanticContentAttributeForceRightToLeft;
    } else {
        cell.contentView.semanticContentAttribute = UISemanticContentAttributeForceLeftToRight;
    }

    return cell; 
}