1

when i custom the tableHeaderView, after i reloadData in viewWillAppear, the tableView contentOffset.y will be changed.

Please help me..


I have log the tableView contentOffset when i will invoke reloadData, this is the log:

2016-03-01 10:51:04:362 ~~[1474:387143] will-TableViewContentOffset: {0, -18} 2016-03-01 10:51:04:363 ~~[1474:387143] did-TableViewContentOffset: {0, -62}

this is how i invoked:

    NHDLog(@"will-TableViewContentOffset: %@", NSStringFromCGPoint(self.tableView.

    [self _reloadTableView];

    NHDLog(@"did-TableViewContentOffset: %@", NSStringFromCGPoint(self.tableView.contentOffset));

In viewDidLoad i have set:

self.edgesForExtendedLayout = UIRectEdgeNone;
self.automaticallyAdjustsScrollViewInsets = NO;
Wilson Yuan
  • 35
  • 1
  • 9

4 Answers4

5

This fixed the same problem for me (thanks to rshinich):

self.tableView.estimatedRowHeight = 0;
self.tableView.estimatedSectionHeaderHeight = 0;
self.tableView.estimatedSectionFooterHeight = 0;
Stephen Kennedy
  • 20,585
  • 22
  • 95
  • 108
Sajjad Hajavi
  • 501
  • 7
  • 9
0

Try to add the following code in viewDidLoad:

In Swift:

self.automaticallyAdjustsScrollViewInsets = false

In Objective-C

self.automaticallyAdjustsScrollViewInsets = NO;
AaoIi
  • 8,288
  • 6
  • 45
  • 87
0

I finally solved the problem by removing the following code:

- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath

Wilson Yuan
  • 35
  • 1
  • 9
0

The unsuitable estimatedRowHeight will make the error y. I change the value to fix my issue, I think you should try too.

Jadian
  • 4,144
  • 2
  • 13
  • 10