SVPullToRefresh icon indicating copy to clipboard operation
SVPullToRefresh copied to clipboard

BUG: TableView section headers hide behind the Navigation bar in iOS 7

Open guidedways opened this issue 11 years ago • 22 comments

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.

guidedways avatar Mar 04 '14 23:03 guidedways

I have the same issue here. Before refresh, it shows correctly, but once refreshed, the first cell was hide behind the navigation bar

jslim89 avatar Mar 18 '14 03:03 jslim89

just add navigationViewController.NavigationBar.translucent = NO into your code, solved!

kavichen avatar Apr 02 '14 03:04 kavichen

if you want to keep the translucent navigation bar you can set the content offset yourself after you call stopAnimating.

gmwood avatar Apr 02 '14 03:04 gmwood

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
}];

Sean-Wang avatar Jun 13 '14 07:06 Sean-Wang

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.

RodBarnes avatar Jun 24 '14 16:06 RodBarnes

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

xiuchundao avatar Jul 09 '14 06:07 xiuchundao

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.

honus avatar Jul 09 '14 09:07 honus

Hi, @honus . I think your suggestion is more elegant. So I take yours. Thank you very much.

xiuchundao avatar Jul 09 '14 13:07 xiuchundao

Hi, @honus thanks. fix SVPullToRefresh in iOS 7 Problem :+1:

edison7500 avatar Aug 02 '14 15:08 edison7500

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...

MikeKogan avatar Aug 21 '14 23:08 MikeKogan

Thanks @honus ,your suggestion is great.

haitaowu avatar Sep 12 '14 12:09 haitaowu

@MikeKogan, your solution is even better. Thanks!

pblondin avatar Oct 20 '14 19:10 pblondin

@honus is correct, simply moving the handler into viewDidAppear did it for me.

Shagans982 avatar Nov 17 '14 01:11 Shagans982

Same here. Moving handler to viewDidAppear did the trick, thanks

aryaxt avatar Mar 22 '15 23:03 aryaxt

@kavichen thanks for the solution. Just add the Swift version which solved my problem: self.navigationController?.navigationBar.translucent = false

bap2pecs0 avatar May 02 '15 04:05 bap2pecs0

I rather keep the nav bar translucent.

self.automaticallyadjustsscrollviewinsets = NO;

and call addPullToRefreshWithActionHandler in viewDidAppear

aryaxt avatar May 27 '15 02:05 aryaxt

Thanks @MikeKogan, your solution is even better.

Sean-Wang avatar Jun 29 '15 14:06 Sean-Wang

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.

liruqi avatar Nov 20 '15 06:11 liruqi

@honus : thank you! It works

haikieu avatar Dec 13 '15 04:12 haikieu

It works, but now the activity loading view don't appear in the beginning. it's behind of the navigation bar.

eduardoarenastk avatar Feb 15 '16 04:02 eduardoarenastk

@honus brilliant!

ryderjack avatar Feb 29 '16 20:02 ryderjack

if put in viewDidAppear..... this will make [self.scrollView triggerPullToRefresh] useless, if you want to trigger immediately after addPullToRefreshWithActionHandler

ngheungyu avatar Jun 11 '16 11:06 ngheungyu