Self Sizing Cells make UITableView jump

烂漫一生 提交于 2019-12-03 02:33:26
igrrik

Okay, I solved both of the problems.

Question 1

I've added these two lines

[cell.contentView setNeedsLayout];
[cell.contentView layoutIfNeeded];

in - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath before return cell

Question 2

The solution appeared to be very simple. I've just needed to implement viewWillDissapear and reload data in it, so the code looks like this

- (void)viewWillDisappear:(BOOL)animated;{
    [super viewWillDisappear:animated];
    [self.tableView reloadData];
}

Solution for me was simple, if it doesn't work for someone, here I found some useful links.
1) UITableView layout messing up on push segue and return. (iOS 8, Xcode beta 5, Swift)
2) http://useyourloaf.com/blog/2014/08/07/self-sizing-table-view-cells.html

Yuchen Zhong

Unfortunately I believe both of the questions that you ask about are IOS bugs.

Question (1)

A easy fix is suggested by this blog.

When the table view is first displayed, you may find some of the cells are not sized properly. But when you scroll the table view, the new cells are displayed with correct row height. To workaround this issue, you can force a reload after the view appears:

Simply add the following to your viewDidAppear method. I have tested it and it works very well.

[self.tableView reloadData];

Question (2)

This second question is a duplicate of this following question:

IOS 8 UITableView self-sizing cells jump/shift visually when a new view controller is pushed

A workaround is suggested by the author of the question himself, which seems okay. However, I have not tried out this one yet.

Okay, I solved it by caching my cell heights in sizeThatFits, and returning that value for estimated cell heights within the delegate. Works beautifully.

Feel free to head over to that question for other proposed solutions.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!