Use UIRefreshControl for UIWebView

前端 未结 8 786
花落未央
花落未央 2021-02-01 08:24

I saw the UIRefreshControl in iOS 6 and my question is if it is possible to refresh a WebView by pulling it down and than let it pop up like in mail? Code I used rabih is the We

8条回答
  •  长发绾君心
    2021-02-01 08:52

    This is how you can use pull down to refresh on UIWebview:

    - (void)viewDidLoad
    {
       [super viewDidLoad];
       // Do any additional setup after loading the view, typically from a nib.
    
       // Make webView a delegate to itself
    
       // I am going to add URL information
       NSString *fullURL = @"http://www.umutcankoseali.com/";
       NSURL *url = [NSURL URLWithString:fullURL];
       NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
       _webView.delegate = (id)self;
       [_webView loadRequest:requestObj];
    
       UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init];
       [refreshControl addTarget:self action:@selector(handleRefresh:) forControlEvents:UIControlEventValueChanged];
       [_webView.scrollView addSubview:refreshControl]; //<- this is point to use. Add "scrollView" property.
    }
    
    -(void)handleRefresh:(UIRefreshControl *)refresh {
       // Reload my data
       NSString *fullURL = @"http://www.umutcankoseali.com/";
       NSURL *url = [NSURL URLWithString:fullURL];
       NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
       [_webView loadRequest:requestObj];
       [refresh endRefreshing];
    }
    

提交回复
热议问题