Detailed explanation of Network Status display of UIWebView

Source: Internet
Author: User

UIWebViewOfNetworkStatus display is described in this article.UIWebViewTo displayWebpageIt is very simple. You only needUIWebViewSend an NSURLRequest. But you will find that it is not user-friendly, because you do not know the current situation,WebpageWhether the file is being loaded or not. Mobile safari is very user-friendly, not only has blue progressbar, but also has a network activity indicator in the status bar.

We also need to add this feature to the application. Adding a network activity indicator is actually very simple. The Code is as follows:

 
 
  1. - (void)showLoading    
  2. {    
  3.     [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];    
  4.     self.theActivityView.hidden = NO;    
  5.     [self.theActivityView startAnimating];    
  6. }    
  7. - (void)hideLoading    
  8. {   
  9.     [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];    
  10.     self.theActivityView.hidden = YES;    
  11.     [self.theActivityView stopAnimating];    
  12. }    
  13. - (void)webViewDidStartLoad:(UIWebView *)webView    
  14. {    
  15.     [self showLoading];    
  16.     NSLog(@"start load");    
  17. }    
  18. - (void)webViewDidFinishLoad:(UIWebView *)webView    
  19. {    
  20.     [self hideLoading];    
  21.     NSLog(@"finish load");    
  22. }    
  23. - (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error    
  24. {    
  25.     [self hideLoading];    
  26.     NSLog(@"error load");    
  27. }    
  28. - (void)showLoading  
  29. {  
  30.  [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];  
  31.  self.theActivityView.hidden = NO;  
  32.  [self.theActivityView startAnimating];  
  33. }  
  34. - (void)hideLoading  
  35. {  
  36.  [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];  
  37.  self.theActivityView.hidden = YES;  
  38.  [self.theActivityView stopAnimating];  
  39. }  
  40. - (void)webViewDidStartLoad:(UIWebView *)webView  
  41. {  
  42.  [self showLoading];  
  43.  NSLog(@"start load");  
  44. }  
  45. - (void)webViewDidFinishLoad:(UIWebView *)webView  
  46. {  
  47.  [self hideLoading];  
  48.  NSLog(@"finish load");  
  49. }  
  50. - (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error  
  51. {  
  52.  [self hideLoading];  
  53.  NSLog(@"error load");  

TheActivityView is an instance of UIActivityIndicatorView. In this way, when the UIWebView is loadedWebpageThere will be an indicator in the status bar and a UIActivityIndicatorView in the UIWebView frame to showWebpageLoading.

After studying how to implement progressbar, no method is found yet. Because there are only a few delegate methods available for UIWebView, it does not help to display the progress bar. You can only find another method.

Summary: DetailsUIWebViewOfNetworkThe content of the Status display is complete. I hope this article will help you.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.