SVPullToRefresh
SVPullToRefresh copied to clipboard
BUG: TableView section headers hide behind the Navigation bar in iOS 7
If you're using a Translucent UINavigationController and you have section headers in your UITableView, the section header moves up and hides under the nav-bar.
I have the same issue here. Before refresh, it shows correctly, but once refreshed, the first cell was hide behind the navigation bar
just add navigationViewController.NavigationBar.translucent = NO into your code, solved!
if you want to keep the translucent navigation bar you can set the content offset yourself after you call stopAnimating.
if ([self respondsToSelector:@selector(automaticallyAdjustsScrollViewInsets)]) {
self.automaticallyAdjustsScrollViewInsets = NO;
UIEdgeInsets insets = self.tableView.contentInset;
insets.top = self.navigationController.navigationBar.bounds.size.height +
[UIApplication sharedApplication].statusBarFrame.size.height;
self.tableView.contentInset = insets;
self.tableView.scrollIndicatorInsets = insets;
}
[tableView addPullToRefreshWithActionHandler:^{
// prepend data to dataSource, insert cells at top of table view
// call [tableView.pullToRefreshView stopAnimating] when done
}];
Under Xcode 5, there are options on the view controller to "Extend Edges" - "Under Top Bars", "Under Bottom Bars". Just uncheck those. This fixed it for me.
I agree with @Sean-Wang 's solution. But another problem occurs. When you pull down, PullToRefresh is triggered, it's right. While InfiniteScrolling will also be triggered, this should not be happened. How can I solved it ? Thanks very much.
I get the solution. see here if anyone need it. #163
The problem appears to be that the pullToRefreshView remembers what the insets are at the time you call addPullRefreshWithActionHandler:. If you do this in viewDidLoad:, the view hasn't been added to the UINavigationController yet so the insets have not been correctly calculated yet. So instead of calling it there, call it in didMoveToParentViewController:
-(void)didMoveToParentViewController:(UIViewController *)parent {
[super didMoveToParentViewController:parent];
if (self.collectionView.pullToRefreshView == nil) {
[self.collectionView addPullToRefreshWithActionHandler:^{
//do refresh
}];
}
}
This way it remembers the correct value to put the content offset back to. If you do this, you don't need to implement @woodappsllc's or @Sean-Wang's suggestions.
Hi, @honus . I think your suggestion is more elegant. So I take yours. Thank you very much.
Hi, @honus thanks. fix SVPullToRefresh in iOS 7 Problem :+1:
This really fixed it without all the baloney of updating insets which becomes problematic during rotation.
Not only do you need: self.automaticallyAdjustsScrollViewInsets = NO;
But this really fixes things on iOS7 without screwing with the content insets etc. Also works properly with custom cells, section headers, etc for the tableview.
self.edgesForExtendedLayout = UIRectEdgeNone;
Until I found this I was about to toss this library in the trash and just code it up myself. Too many bugs here for something that should be simple, but that's the Crapple way - make the simple complex. All of this is a piece of cake on Android...
Thanks @honus ,your suggestion is great.
@MikeKogan, your solution is even better. Thanks!
@honus is correct, simply moving the handler into viewDidAppear did it for me.
Same here. Moving handler to viewDidAppear did the trick, thanks
@kavichen thanks for the solution. Just add the Swift version which solved my problem: self.navigationController?.navigationBar.translucent = false
I rather keep the nav bar translucent.
self.automaticallyadjustsscrollviewinsets = NO;
and call addPullToRefreshWithActionHandler in viewDidAppear
Thanks @MikeKogan, your solution is even better.
You need to add action handler in - viewDidAppear method (or after), as you can get correct scroll view contentInset then. In - viewDidLoad, your scroll view has not set the final contentInset after in iOS7 or later, typically all zeros.
- addPullToRefreshWithActionHandler method record current scrollview contentInset as originalTopInset, originalBottomInset, and reset to that contentInset after - stopAnimating.
@honus : thank you! It works
It works, but now the activity loading view don't appear in the beginning. it's behind of the navigation bar.
@honus brilliant!
if put in viewDidAppear..... this will make [self.scrollView triggerPullToRefresh] useless, if you want to trigger immediately after addPullToRefreshWithActionHandler