My app has a UITableView
. That UITableView has a header view, which is a UIWebView
.
By default, scroll views have their scrollsToTop
property set to YES
, which will enable the user to tap the status bar to scroll to the top of the scroll view.
When there are two scroll views embedded in one view, that both have their scrollsToTop
property set to YES
, tapping the status bar does nothing.
The solution is to set one of the scrollsToTop
properties to NO
. That re-enables tapping the status bar.
Now here's the problem: UIWebView doesn't expose it's scroll view, and as a result, there is no access to it's scrollsToTop
property. I only want the table view to scroll to the top when the status bar is tapped, not the web view.
Does anyone know how I can achieve this?
There's now a scrollView property, which is preferred:
myWebView.scrollView.scrollsToTop = YES;
This question contains the answer:
iPhone OS: Tap status bar to scroll to top doesn't work after remove/add back
I couldn't find it previously since it was asked differently and on a slightly different topic, but the result is the same.
So the outcome was to walk through the subviews until you find the scroll view. I've done this before in other apps and didn't think of it in this case. It should be App-Store-Safe, as I have apps on the store that use this idea.
A category on UIWebView to enable or disable scrolling to top:
@implementation UIWebView (UIWebViewScrollToTopAdditions)
- (void)setScrollsToTop:(BOOL)scrollsToTop
{
if ([[self subviews] count] > 0)
{
UIScrollView *scrollView = (UIScrollView *)[[self subviews] objectAtIndex:0];
if ([scrollView respondsToSelector:@selector(setScrollsToTop:)])
{
[scrollView setScrollsToTop:scrollsToTop];
}
}
}
@end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With