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.scrollsToTop = true
and still nothing happens.
I know Apple significantly changed the status bar in iOS7, but did those changes break the scrollsToTop
functionality?
Update
In response to a comment in one of the answers, I tested to ensure that my collection view was indeed the only scrollView on the screen, and it was:
(lldb) po [self.view recursiveDescription]
<UIView: 0x1092ddf0; frame = (0 0; 320 568); autoresize = W+H; layer = <CALayer: 0x109357e0>>
| <UICollectionView: 0x11351800; frame = (0 0; 320 568); clipsToBounds = YES; opaque = NO; autoresize = W+H; gestureRecognizers = <NSArray: 0x10966080>; layer = <CALayer: 0x109623a0>; contentOffset: {0, -64}> collection view layout: <UICollectionViewFlowLayout: 0x10940a70>
| | <UIImageView: 0x10965fa0; frame = (0 564.5; 320 3.5); alpha = 0; opaque = NO; autoresize = TM; userInteractionEnabled = NO; layer = <CALayer: 0x10965ee0>> - (null)
| | <UIImageView: 0x10948f60; frame = (316.5 561; 3.5 7); alpha = 0; opaque = NO; autoresize = LM; userInteractionEnabled = NO; layer = <CALayer: 0x10966030>> - (null)
Update #2
Not sure if it matters, but I'm using a standard iOS7 NavigationController where the navigationBar is transparent and applies a blur to my collection/tableViews as they scroll underneath.
Update #3
Figured it out. Turns out I did have more than one scrollView on the screen. My app has a left drawer menu underneath the main part of the app, and that menu has a tableView for the options. I simply set self.menuTable.scrollsToTop = false
and everything worked as expected throughout the rest of the app. Didn't have to implement the scrollView Delegate methods or anything.
This always works for me:
My problem was that I had a
UITextView
withscrollsToTop
set toYES
, so myUITableView
wasn't responding to the gesture. In short, make check all other scrollable views.If your table cells are dynamic, remove the following:
Create a new function as follows:
Call the function above in
- (void)viewDidLoad
Now enable ScrollsToTop for your table view as follows:
Do you have more than one scroll view/table view/collection view on screen? If so, only one of them can have
scrollsToTop
set toYES
, 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: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.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.