ios – 对UIWebView使用UIRefreshControl

前端之家收集整理的这篇文章主要介绍了ios – 对UIWebView使用UIRefreshControl前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我在iOS 6中看到了UIRefreshControl,我的问题是如果可以通过拉下来刷新WebView,而不是像邮件一样弹出呢?
代码我用的是rabih是WebView:
  1. UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init];
  2. [refreshControl addTarget:self action:@selector(handleRefresh:) forControlEvents:UIControlEventValueChanged];
  3. [rabih addSubview:rabih];

解决方法

这是你如何使用下拉刷新UIWebview:
  1. - (void)viewDidLoad
  2. {
  3. [super viewDidLoad];
  4. // Do any additional setup after loading the view,typically from a nib.
  5.  
  6. // Make webView a delegate to itself
  7.  
  8. // I am going to add URL information
  9. NSString *fullURL = @"http://www.umutcankoseali.com/";
  10. NSURL *url = [NSURL URLWithString:fullURL];
  11. NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
  12. _webView.delegate = (id)self;
  13. [_webView loadRequest:requestObj];
  14.  
  15. UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init];
  16. [refreshControl addTarget:self action:@selector(handleRefresh:) forControlEvents:UIControlEventValueChanged];
  17. [_webView.scrollView addSubview:refreshControl]; //<- this is point to use. Add "scrollView" property.
  18. }
  19.  
  20. -(void)handleRefresh:(UIRefreshControl *)refresh {
  21. // Reload my data
  22. NSString *fullURL = @"http://www.umutcankoseali.com/";
  23. NSURL *url = [NSURL URLWithString:fullURL];
  24. NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
  25. [_webView loadRequest:requestObj];
  26. [refresh endRefreshing];
  27. }

猜你在找的iOS相关文章