UITableView scroll to top when tapping status bar

2019-02-01 18:16发布

问题:

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.

回答1:

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.



回答2:

Thanks for all, i resolved this problem by removing all other UITableView from the parent ViewController, and then auto scroll to top was working for this UITableView..

thanks