Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITableView scroll to top when tapping status bar at top of the screen

I inserted a UITableView inside another UIViewController's view. but when I tap the status bar at the top of the screen; the table view doesn't scroll to the top which is the expected behavior within iOS apps.

I tried :

[self.tableView setScrollsToTop:YES];

but the tableview still not scroll to top when tap the top of the screen.

like image 350
yasserislam Avatar asked Jan 21 '12 07:01

yasserislam


People also ask

How do I scroll to the top of my iPhone?

iPhone has had this feature for a long time, but many users aren't aware of it. You can tap the clock in the status bar to scroll to top in any app on your iPhone. If you have a iPhone X or newer devices, the ones with a “notch”, you can tap on either sides of the notch to scroll to the top.

How do I scroll to top tableView?

To scroll to the top of our tableview we need to create a new IndexPath . This index path has two arguments, row and section . All we want to do is scroll to the top of the table view, therefore we pass 0 for the row argument and 0 for the section argument. UITableView has the scrollToRow method built in.

Is UITableView scrollable?

UITableView scrolls back because it's content size is equal to it's frame (or near to it). If you want to scroll it without returning you need add more cells: table view content size will be large then it's frame.

How can I tell if a tableView is scrolling?

Since a scrollView has a panGesture we can check the velocity of that gesture. If the tableView was programmatically scrolled the velocity in both x and y directions is 0.0. By checking this velocity we can determine if the user scrolled the tableView because the panGesture has a velocity.


1 Answers

You have to set scrollsToTop to NO on all the other scroll views in your hierarchy. If more than one scroll view has scrollsToTop set to YES, none of them will scroll to top when the status bar is touched. This is mentioned in the documentation of the scrollsToTop property.

Keep in mind that this also applies to any subclasses of UIScrollView in your view hierarchy, and that UITableView, UIContainerView, and UITextView are subclasses of UIScrollView.

like image 58
rob mayoff Avatar answered Nov 02 '22 23:11

rob mayoff