I have implemented a \"Pull to refresh\" in my tableView like the iPhone app Twitter or Facebook.
My tableView has sections with head views. When the tableView is in \"Refre
I had the same problem when using contentInset and fixed it by adding code to scrollViewDidScroll: to update the contentInset dynamically while in the "loading" state.
if( refreshState == kLoading ) {
if( scrollView.contentOffset.y >= 0 )
scrollView.contentInset = UIEdgeInsetsZero;
else
scrollView.contentInset = UIEdgeInsetsMake( MIN( -scrollView.contentOffset.y, kPullHeight ), 0, 0, 0 );
}
Looks like an UIKit bug. Found a workaround:
// your initial inset
let kInset = 40.0
func scrollViewDidScroll(_ scrollView: UIScrollView) {
let offset = scrollView.contentOffset.y
if (offset < 0) {
scrollView.contentInset = UIEdgeInsets(top: kInset, left: 0.0, bottom: 0.0, right: 0.0)
} else {
scrollView.contentInset = .zero
}
}
Try this way to add push view controller.
Then assign your table view and refresh controllers to tableview controller's properties.
UITableViewController *newTableViewController = [[UITableViewController alloc] init];
newTableViewControler.tableView = <yourTableView>;
<yourRefreshController> = [[UIRefreshControl alloc] init];
[<yourRefreshController> addTarget:self
action:@selector(refreshTableView:)
forControlEvents:UIControlEventValueChanged];
newTableViewController.refreshControl = _chatListRefreshControl;
[self addChildViewController:newTableViewController];
When doing this, I usually use the table-wide header in UITableView instead:
@property(nonatomic, retain) UIView *tableHeaderView
...instead of contentInsets. There were a lot of bugs with contentInsets all the way back to iOS 2.x days, and I'm not sure they've all been fixed. Is there a reason you can't use a table header?