Can't get scrollsToTop working on iOS7

前端 未结 6 442
我在风中等你
我在风中等你 2020-12-29 04:15

I\'m targeting iOS7 in my latest app, and tapping on the status bar doesn\'t seem to scroll a tableView or collectionView to the top.

I\'ve set self.tableView.

相关标签:
6条回答
  • 2020-12-29 04:54

    Do you have more than one scroll view/table view/collection view on screen? If so, only one of them can have scrollsToTop set to YES, otherwise iOS7 will not scroll any of them to the top.

    You can also implement the UIScrollViewDelegate method scrollViewShouldScrollToTop: and return YES if the passed in scroll view is equal to the one that you want to scroll to the top:

    - (BOOL) scrollViewShouldScrollToTop:(UIScrollView*) scrollView {
        if (scrollView == self.myTableView) {
            return YES;
        } else {
            return NO;
        }
    }
    
    0 讨论(0)
  • 2020-12-29 04:57

    The short answer is there's nothing different in iOS7. As long as there isn't more than one UIScrollView loaded, your tableView or collectionView will scroll to the top when the user taps the status bar. The key here is loaded; another scrollView doesn't necessarily have to be on screen to conflict with another scrollView that is.

    Sliding drawers in the left/right are very popular these days, and this was the reason for my problem. I have a menu containing my navigation options, and these are all held by a UITableView. I had to make sure that I set menuTable.scrollsToTop = false before I could get things working in the other parts of my app.

    0 讨论(0)
  • 2020-12-29 05:07

    for others :

    Remember that the scroll view you are searching can also be a UIWebView..not just UITableView. Another important thing is that it's not only about VISIBLE scrollViews, but LOADED scrollviews.

    If you don't find the scrollView, you can always insert UITableView test table, immediately when app is starting, check if it's scroll to top, and then load more and more views, until the test table stop scrolling to top.

    0 讨论(0)
  • 2020-12-29 05:16

    If your table cells are dynamic, remove the following:

    - (BOOL)scrollViewShouldScrollToTop:(UIScrollView *)scrollView
    {
        return YES;
    }
    

    Create a new function as follows:

    - (void) disableScrollsToTopPropertyOnAllSubviewsOf:(UIView *)view {
        for (UIView *subview in view.subviews) {
            if ([subview isKindOfClass:[UIScrollView class]]) {
                ((UIScrollView *)subview).scrollsToTop = NO;
            }
            [self disableScrollsToTopPropertyOnAllSubviewsOf:subview];
        }
    }
    

    Call the function above in - (void)viewDidLoad

    [self disableScrollsToTopPropertyOnAllSubviewsOf:self.view];
    

    Now enable ScrollsToTop for your table view as follows:

    [myTableView setScrollsToTop:YES];
    
    0 讨论(0)
  • 2020-12-29 05:17

    This always works for me:

    [self.tableView scrollRectToVisible:CGRectMake(0, 0, 1, 1) animated:YES];
    
    0 讨论(0)
  • 2020-12-29 05:18

    My problem was that I had a UITextView with scrollsToTop set to YES, so my UITableView wasn't responding to the gesture. In short, make check all other scrollable views.

    0 讨论(0)
提交回复
热议问题