Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to refresh a UIWebView by a "pull down and release" gesture?

I know that this is possible in the Tweetie for iPhone or the xkcd iPhone app, but they are using a table. Any idea if this can be done for a simple UIWebView as well? I'm aware of the Javascript suggestions in this SO question, but what about making that natively?

like image 988
phi Avatar asked Jul 11 '10 15:07

phi


3 Answers

To retrieve scroll events on UIWebView I personnaly use this code to get the scrollview that is inside the UIWebView :

- (void) addScrollViewListener
{
    UIScrollView* currentScrollView;
    for (UIView* subView in self.myWebView.subviews) {
         if ([subView isKindOfClass:[UIScrollView class]]) {
            currentScrollView = (UIScrollView*)subView;
            currentScrollView.delegate = self;
        }
    }
}

It's working. You can also use it to call [(UIScrollView*)subView setContentOffset:offSet animated:YES]; The only problem may be not to pass Apple code checking. I don't know yet since I'm still in coding phase.

Anyone tried that yet ?

like image 139
CedricSoubrie Avatar answered Sep 22 '22 18:09

CedricSoubrie


FYI, iOS 5 has officially introduced the property scrollView in UIWebView. I tested it. It worked perfectly with EGO's pull and refresh code. So the problem is no longer a problem for any iOS 5 devices.

For downward compatibility, you still need @CedricSoubrie's code though.

like image 43
Di Wu Avatar answered Sep 24 '22 18:09

Di Wu


To tell the truth, UIWebVIew class has an undocumented getter method called _scrollView; So the code goes:

scrollView = [webView _scrollView];

like image 42
Geri Borbás Avatar answered Sep 25 '22 18:09

Geri Borbás