3

I have a UITableView of type plain table view with two sections and a dynamic number of rows. Also I am returning a UIView for the section header.

Everything works perfect except when the table reloads. The section header position moves to a random position until the view begins to scroll.

Autolayout within the header view and super view seem not violating. I have set the table footer view either nil or show paginating animation. And the table view is within a scroll view.

Any suggestion or solution why this glitch occurs for section header. And this glitch only occurs in iOS 9

pre
  • 3,475
  • 2
  • 28
  • 43
Anand Prem
  • 397
  • 5
  • 15
  • Sry actually its about a thousand+ line code. I'm sure that I'm not modifying the content inset or offset manually. But I doubt setting footer view changes the content offset or inset. Before reloading the table view the section header is at some point 1300 (content offset.y) but after reloads it get some 3000 or something like that. Viewing the clipped view hierarchy shows its somewhere in the bottom. – Anand Prem Jan 09 '16 at 13:01
  • Also when began to scroll the table view , the section header stick to the original position – Anand Prem Jan 09 '16 at 13:02
  • => You try change your tableview style to 'grouped' in order to keep the section from moving. => see below post it might be helps to you :- http://stackoverflow.com/questions/8306792/uitableview-reload-section – Akash Jan 09 '16 at 13:09
  • I'm using plain table view because I want section header to stick at top. – Anand Prem Jan 09 '16 at 13:15
  • And thanks @Akash that thread seems to be useful, I will try that – Anand Prem Jan 09 '16 at 13:16
  • @AnandPrem did you find a solution to this ? We are experiencing a similar glitch. Any help would be appreciated, thank you – MDMonty Nov 29 '16 at 10:11
  • @MDMonty Initially I have added the refresh controller as a subview of my tableview, later I have created a table view controller and added table view as it's subview, then added table view controller's refresh controller property. It's fixes my issue. – Anand Prem Nov 29 '16 at 12:40

2 Answers2

5

Problem for me was independently from refresh control, although it is part of my view controller. It was related to estimatedRowHeight and rowHeight.

I found an empirical solution. My issue happened when going back and forth between view controller and the tableview reloaded.

Because my cells have variable height, I had:

self.tableView.rowHeight = UITableViewAutomaticDimension;
self.tableView.estimatedRowHeight = 44.0f;

so I can deal with cell autoresize. Apparently the problem was with the estimatedRowHeight. When I changed the value with the maximum cell row height the glitch disappeared. The table section wasn't jumping anymore. I used the view inspector to calculate the row height based on my worst use case.

Note #1

I don't know how it performs with a thousand cells. estimatedRowHeight should be used to calculate the entire content offset so considering the worst case might be inefficient.

Note #2

When calculate the maximum cell height keep in mind to consider the case when the font size can be increased by the system preference, if the cell is registered to these changes.

mulp
  • 115
  • 1
  • 9
1

My issues get resolved as follows.

Initially I have added refresh controller as a subview of table view.

_chatListRefreshControl = [[UIRefreshControl alloc] init];
_chatListRefreshControl.transform = CGAffineTransformMakeScale(0.7, 0.7);
[_chatListRefreshControl addTarget:self
                            action:@selector(refreshChatListView:)
                  forControlEvents:UIControlEventValueChanged];
[self.myChatsTableView addSubview:_chatListRefreshControl];

I have modified that to as follows: Changed the refresh indicator from table view to table view controller's property.

UITableViewController *chatTableViewcontroller = [[UITableViewController alloc] init];
    chatTableViewcontroller.tableView = self.myChatsTableView;
    _chatListRefreshControl = [[UIRefreshControl alloc] init];
    _chatListRefreshControl.transform = CGAffineTransformMakeScale(REFRESH_INDICATOR_SCALE_FACTOR, REFRESH_INDICATOR_SCALE_FACTOR);
    [_chatListRefreshControl addTarget:self action:@selector(refreshChatListView:) forControlEvents:UIControlEventValueChanged];
    chatTableViewcontroller.refreshControl = _chatListRefreshControl;
    [self addChildViewController:chatTableViewcontroller];
Anand Prem
  • 397
  • 5
  • 15