Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITableView's, UIWebViews and the scrollsToTop Property = Trouble

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?

like image 810
Jasarien Avatar asked Apr 23 '10 08:04

Jasarien


2 Answers

There's now a scrollView property, which is preferred:

myWebView.scrollView.scrollsToTop = YES;
like image 199
Aaron Brager Avatar answered Sep 27 '22 22:09

Aaron Brager


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
like image 35
Jasarien Avatar answered Sep 27 '22 23:09

Jasarien