Scroll to top of UITableView by tapping status bar

2019-01-21 00:57发布

I know there's tons of code out there to scroll a tableview to the top, but I want to do this when the top status bar is tapped, just like in Apple's native apps. Is this possible?

9条回答
兄弟一词,经得起流年.
2楼-- · 2019-01-21 01:27

Like Mark said, you can only have one subclass of UIScrollView (usually the table view) that has the scrollsToTop property set to TRUE. Likely you have others, typically UITextView in your view. Just set their scrollsToTop property to FALSE and you're good to go.

查看更多
虎瘦雄心在
3楼-- · 2019-01-21 01:32

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

When this does NOT work is when you have a UIScrollView (or descendant class like UITextView) object embedded inside another UIScrollView class (like UITableView). In this case, set scrollsToTop on the embedded UIScrollView class to NO. Then the tap-the-status-bar behavior will work.

查看更多
劫难
4楼-- · 2019-01-21 01:33

If you came from Google and need a complete checklist:

  1. Check that you've set scrollsToTop=YES (per Mark's suggestion) on your UITableView
  2. Make sure that you've set scrollsToTop=NO on all OTHER UITableViews / UIScrollViews / UITextViews in your window, so that they're not intercepting the click. I've found myself printing out all the views in my window many times to debug this...
  3. Make sure that your table view is at 0/0 (x/y coordinates) within the window - this is how the system knows that it should pass the message
查看更多
登录 后发表回答