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

4

8

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?

Spannew answered 11/7, 2010 at 15:47 Comment(0)
U
5

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.

Unfriended answered 30/10, 2011 at 10:17 Comment(0)
B
13

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 ?

Buckwheat answered 3/11, 2010 at 10:56 Comment(3)
I know from a certain developer that she has passed the approval process whilst having something like this in the code, for removing the UIWebView shadows (you'd have to get the UIScrollView for that as well)Approval
Works like charm! (Though I didn't submit my app to App Store yet)Unfriended
Beware, this code doesn't work in iOS 5 because the scrollView of the webView class changed. Use this code instead : if ([subView isKindOfClass:[UIScrollView class]]) I changed my original post so the code is compatible with iOS 5Buckwheat
U
5

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.

Unfriended answered 30/10, 2011 at 10:17 Comment(0)
L
1

To get a reference for the UIScrollView in UIWebView, simply search it by iterating trough subviews.

for(id eachSubview in [webView subviews]){
        if ([eachSubview isKindOfClass:[UIScrollView class]]){
            scrollView = eachSubview;
            break;
        }
}

After that you can easily wire up things to your EGORefreshTableHeaderView interface with the UIWebView and the UIScrollView delegate callbacks.

Laurettelauri answered 3/3, 2011 at 11:22 Comment(0)
L
1

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

scrollView = [webView _scrollView];

Laurettelauri answered 3/3, 2011 at 12:34 Comment(1)
Doing things this way is using a "private API". If you use CedricSoubrie's method above, you are using only public methods.Perry

© 2022 - 2024 — McMap. All rights reserved.