0

How can I make a "Pull to refresh" in iOS 5 for an UIWebView ? I can't find a tutorial.

I have got a WebView in a Tab Bar application, and I want to refresh the WebView with a "Pull to refresh" like Twitter.

Where can I find a complete tutorial ?

Thank you

user1530090
  • 705
  • 1
  • 5
  • 6
  • 'pull to refresh' really doesn't make sense for a UIWebView, seeing as bounce scrolling upwards is so common, it would really get annoying after a while. – Richard J. Ross III Jul 18 '12 at 20:18
  • Maybe you can try searching Google or SO: http://stackoverflow.com/questions/3223627/how-to-refresh-a-uiwebview-by-a-pull-down-and-release-gesture –  Jul 18 '12 at 20:19
  • @RichardJ.RossIII it quite does, see my comment... –  Jul 18 '12 at 20:23
  • I used this but it doesn't show the Pull to refresh :s – user1530090 Jul 18 '12 at 20:29
  • @H2CO3 I Know it's possible, but what I was questioning was is it HIG-compliant? And it may be possible that there is a better solution using JavaScript. – Richard J. Ross III Jul 18 '12 at 20:30
  • @RichardJ.RossIII are you kidding me? JavaScript for graphics when you can have damn fast native code? –  Jul 18 '12 at 20:32
  • @H2CO3 the OP said he couldn't get the link you provided to work, so I provided a possible alternate solution. I'm not saying that JavaScript would have better performance, but if he can't use a native solution (for whatever reason) that is the next-best thing. – Richard J. Ross III Jul 18 '12 at 20:42
  • If I want to use Obj. C., how can I do it ? Thx – user1530090 Jul 18 '12 at 20:46
  • @RichardJ.RossIII that's definitely true, but in first place he should try to get the native solution work -- if the exact same thing works for somebody else, then the error is at OP... –  Jul 18 '12 at 20:47

3 Answers3

0

I cannot provide a tutorial, maybe I'll write one but I think it was quite simple, I did this slightly modifying SPPullView.

Here you can grab the files (SPPullView.m and SPPullView.h).

Relevant code in the main UIViewController is something like:

- (void)viewDidLoad
{   
    [super viewDidLoad];
    self.pullView = [[SPPullView alloc] initWithScrollView:self.webView.scrollView];
    [self.pullView setDelegate:self];
    [self.webView.scrollView addSubview:self.pullView];    
    [self.webView.scrollView setDelegate:self];
    for (UIView *subview in [self.webView.scrollView subviews] ) {
       subview.userInteractionEnabled = NO; // used to disable copy/paste, etc inside the webview
    }
    //[self doYourStuff];
}

//Called when the user pulls to refresh (this is when you should update your data)
- (void) pullViewShouldRefresh: (SPPullView *) view {
    [self updateYourStuff];
}

You can also add some logic or properties to prevent the user zooming, or deactivate the pull view temporarily while zooming.

jllodra
  • 1,348
  • 1
  • 14
  • 22
0

This works very well: http://blog.gomiso.com/2012/03/22/yet-another-pull-to-refresh-library/

pyra
  • 31
  • 3
0

I wrote this code and it is working fine. This may help you.

- (void)viewDidLoad
{
   [super viewDidLoad];

   NSString *fullURL = URL you want to hit;
   NSURL *url = [NSURL URLWithString:fullURL];
   NSURLRequest *requestObject = [NSURLRequest requestWithURL:url];
   webView.delegate = (id)self;
   [webView loadRequest:requestObject];

   UIRefreshControl *refreshControlOnPull = [[UIRefreshControl alloc] init];
   [refreshControlOnPull addTarget:self action:@selector(handleRefresh:) forControlEvents:UIControlEventValueChanged];
   [webView.scrollView refreshControlOnPull]; //<- this is point to use. Add "scrollView" property.
}

-(void)handleRefresh:(UIRefreshControl *)refresh {
   // Reload my data
   NSString *fullURL = The Url you want to hit;
   NSURL *url = [NSURL URLWithString:fullURL];
   NSURLRequest *requestObject = [NSURLRequest requestWithURL:url];
   [webView loadRequest:requestObject];
   [refresh endRefreshing];
}
Jeet
  • 15
  • 6