Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS: How to reload cell at indexPath without animation?

I have UITableView with cells. When i select cell - height increased, when i select this cell again - height decreased. In method "didSelectRowAtIndexPath" i use this -

NSArray *indArr = [[NSArray alloc] initWithObjects:(NSIndexPath*)[timer userInfo], nil];
[self.tableView reloadRowsAtIndexPaths:indArr withRowAnimation:UITableViewRowAnimationFade];

But "UITableViewRowAnimationFade" animation has faded effect, and cell is flickered. I tried another animations, but they also unsuitable(

How i can avoid this effect and update cell without animation?

like image 470
Nubaslon Avatar asked Nov 30 '22 00:11

Nubaslon


2 Answers

Setting the row animation to .None doesn't work - there is still stuff going on and moving about. In my case, some cells changed height, which caused the table view to scroll.

To hold perfectly still, do this:

    UIView.performWithoutAnimation({ 
        let loc = tableView.contentOffset
        tableView.reloadRows(at: [indexPath], with: .none)
        tableView.contentOffset = loc
    })
like image 78
n13 Avatar answered Dec 07 '22 01:12

n13


Try this.

UIView.setAnimationsEnabled(false)

self.yourTableView.beginUpdates()

self.yourTableView.reloadRows(at: yourIndexPath, with:UITableViewRowAnimation.none)

self.yourTableView.endUpdates()
like image 38
Muthukumar V Avatar answered Dec 06 '22 23:12

Muthukumar V