开发者

UITableView reloadRowsAtIndexPaths performing animation when it shouldn't

开发者 https://www.devze.com 2023-02-01 11:53 出处:网络
I\'m using a UITa开发者_StackOverflow中文版bleView in my iOS app, and have been seeing a strange issue recently.

I'm using a UITa开发者_StackOverflow中文版bleView in my iOS app, and have been seeing a strange issue recently.

Suppose my table is structured as follows:

section 1 header
row 
section 2 header
section 3 header
row
row 
...

(Note that section 2 has no rows)

I'm performing updates to the rows in my table via

    [self.tv beginUpdates];
    [self.tv reloadRowsAtIndexPaths:ip withRowAnimation:UITableViewRowAnimationNone];
    [self.tv endUpdates];

I don't want any animations taking place. I just want the row to update. The issue is that this strategy works for every row and section in the my table except section 3, row 1: the first row of the last section. When I update this row (which is indeed using the correct indexPaths), rather than get no animation, the row does this little jump, like it's sliding in a new row to replace the old one or something. The row slides up ever so slightly, then back down, as if I was inserting a row. I'm guessing it has something to do with the header calculations, but I do return correct values for heightForHeaderInSection.

Has anyone seen this behavior?


I wonder if the beginUpdates and endUpdates are necessary in this reload only scenario.


I had the same problem. The solution was to fetch the cell from the table using:

UITableViewCell* cell = [self.tableView cellForRowAtIndexPath:indexPath]

and then refresh it manually using a custom setup method or by simply calling:

[cell setNeedsLayout]

For more info, see:

UITableView reloadRowsAtIndexPaths graphical glitch

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号