UITableView, UIWebViews and scrollsToTop Property = Trouble

My application has a UITableView . This UITableView takes the form of a header, which is a UIWebView .

By default, in scroll views, their scrollsToTop property scrollsToTop set to YES , which allows the user to touch the status bar to go to the top of the scroll.

When there are two types of scrolling embedded in one view, both have the scrollsToTop property set to YES , pressing the status bar does nothing.

The solution is to set one of the scrollsToTop properties to NO . This will activate the status bar again.

Now here is the problem: UIWebView does not show its scrolling, and as a result there is no access to it scrollsToTop . I just want the table view to appear at the top when the status bar is displayed, not the web view.

Does anyone know how I can achieve this?

+6
iphone uitableview scroll uiscrollview uiwebview
source share
4 answers

Now there is a scrollView property, which is preferred:

 myWebView.scrollView.scrollsToTop = YES; 
+3
source share

This question contains the answer:

iPhone OS: tap the status bar to scroll up, does not work after deleting / adding

I could not find it before, since it was asked differently and on a slightly different topic, but the result is the same.

So the result was to go through the subviews until you find the scroll. I did this before in other applications and did not think about it in this case. This should be an App-Store-Safe, since I have apps in the store that use this idea.

Category in UIWebView to enable or disable scrolling at the 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 
+3
source share

This often happens because all scrollviews have a default value. When new scroll views or web views are created, they will have scrollsToTop to YES. I wrote a simple category for this particular problem:

 -[UIScrollView makeOnlyThisScrollViewScrollToTopOnStatusBarTap]; 

https://gist.github.com/hfossli/6776203

It basically sets scrollsToTop to NO for all other scrollViews than the one you specify + to take care of the default value. Good luck

+2
source share

Have you tried the delegate method from UIScrollViewDelegate scrollViewShouldScrollToTop ?

0
source share

All Articles