views:

483

answers:

2

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?

A: 

Have you tried the delegate method from UIScrollViewDelegate scrollViewShouldScrollToTop?

gabac
It doesn't appear to work. I initially tried implementing that method along side the UIWebViewDelegate methods, but I didn't think that would work because the web view itself is the scroll view delegate, rather than the web view's delegate. So then I subclassed UIWebView and implemented, but still no luck. It doesn't seem to work.
Jasarien
Further investigation: It seems that UIWebView itself doesn't respond to the scroll view delegate methods. Perhaps some other internal object is the scroll view delegate?
Jasarien
A: 

This question contains the answer:

http://stackoverflow.com/questions/1361614/iphone-os-tap-status-bar-to-scroll-to-top-doesnt-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
Jasarien