Scroll up the UITableView pages by tapping the status bar

I know that there is a tone of code to scroll the table at the top, but I want to do this when the top status bar is displayed, exactly the same as in Apple’s own applications. Is it possible?

+49
ios objective-c scroll tableview statusbar
Aug 23 '11 at 18:38
source share
8 answers

You will get this for free, but you should check that the scrollsToTop attribute of your UITableView is YES.

If this does NOT work, if you have a UIScrollView object (or a descendant like a UITextView) embedded in another UIScrollView class (like a UITableView ). In this case, set scrollsToTop for the built-in UIScrollView class to NO. Then the behavior of tap-the-status-bar will work.

+139
Aug 23 '11 at 18:41
source share

If you came from Google and you need a complete checklist:

  • Make sure you set scrollsToTop = YES (as requested by Mark) in your UITableView
  • Make sure you set scrollsToTop = NO in all other UITableViews / UIScrollViews / UITextViews in your window so that they do not intercept the click. I found myself printing all kinds of in my window many times to debug this ...
  • Make sure your table view is at 0/0 (x / y coordinates) in the window - this is how the system knows that it should send a message
+30
Apr 10 '13 at
source share

Using the information provided in other answers, I added the following code to my UITableViewController so that it works:

 - (void) viewDidLoad
 {
     [super viewDidLoad];

     for (UITextView * view in self.view.subviews) {
         if ([view isKindOfClass: [UITextView class]]) {
             view.scrollsToTop = NO;
         }
     }

     self.tableView.scrollsToTop = YES;
 }

This scans all views in the UITableViewController hierarchy and disables scrollsToTop in all UITextViews that catch the touch event. Then, ensuring that the tableView still gets the touch.

You can change this to iterate over other UITableViews / UIScrollViews / UITextView, which can also be intercepted.

Hope this helps!

+6
Feb 07 '14 at 23:10
source share

I had the same problem but was fixed with the following steps:

  • Set scrollsToTop = YES to view the table you want to scroll up.
  • set scrollsToTop = NO for all other table or collection or scroll views.
  • If any of your cell tableview has a collection view. Make sure that you also set scrollsToTop NO to represent the collection.

If your view controller / navigation controller is added as a subobject on another view controller, make sure you set it as a child controller.

+5
Nov 27 '15 at 1:28
source share

As Mark said, you can only have one subclass of UIScrollView (usually this is a table view) with the scrollsToTop property set to TRUE. You probably have others, usually a UITextView in your opinion. Just set the scrollsToTop property to FALSE, and you will be fine.

+2
Nov 02 '13 at 2:55
source share

I know this is pretty old, but hope this can help. Following what @MarkGranoff said, scrollsToTop does not work if more than one UIScrollView or its subclasses is YES (the default value), a health check is probably worth checking who actually messed up this behavior. The simple method below is over the views of your view and registers the scrollsToTop value for the entire UIScrollView in your view. It is preferable to call viewDidAppear in your method.

 - (void)checkForScrollViewInView:(UIView *)view { for (UIView *subview in [view subviews]) { if ([subview isKindOfClass:[UIScrollView class]]) { NSLog(@"scrollsToTop enabled: %i in scroll view %@", ((UIScrollView *)subview).scrollsToTop, subview); } if (subview.subviews.count > 0) { [self checkForScrollViewInView:subview]; } } } 

This is really debugging code. When you find the scrollsToTop value for each of the UIScrollView subclasses, make sure that only one of them is set to YES.

+2
Aug 21 '15 at 4:07
source share

In the UIScrollView header file:

// When the user selects the status bar, the touch view that is closest to the status bar will scroll up, but only if its scrollsToTop property is YES, its delegate does not return NO from shouldScrollViewScrollToTop , and it is not yet at the top. // On the iPhone, we perform this gesture only if there is one screen scroll view with scrollsToTop == YES. If more than one is found, none of them will scroll.

0
Aug 26 '16 at 11:47
source share

For example, if you have a table view and scroll view, such as tags such as

enter image description here

you should do something like this in viewDidLoad

 self.tableView.scrollsToTop = true self.tagsView.scrollsToTop = false 
0
Dec 03 '16 at 14:18
source share



All Articles