Show progress bar until it load the data in UIWebView IOS7

后端 未结 2 1504
自闭症患者
自闭症患者 2020-12-18 15:17

Hi in my application i have UIWebView which loads the pdf file using URL its very large file its taking too much time to load. Now i want show the

相关标签:
2条回答
  • 2020-12-18 15:59

    Yes why not, use UIWebView delegate method

    - (void)viewDidLoad
    {
       [super viewDidLoad];
    
       webview.delegate=self; //Assign Delegate
    
       [webview loadRequest:myRequest];
    
       [self showProgress];//Show Progress
    
    }
    

    Use delegates as below

    - (void)webViewDidFinishLoad:(UIWebView *)webView{
        if(!webView.isLoading){ //This ensures whether the webview has finished loading..
           [self hideProgress];
        }
    }
    - (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error{
       [self hideProgress];
    }
    

    Cheers.

    0 讨论(0)
  • 2020-12-18 16:12

    You should start/stop the progressbar in webview delegate methods.

    Add following line in your viewDidLoad.

    webview.delegate = self;
    

    Add following functions in your controller...

    -(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
    {
        //Start the progressbar.. 
        return YES;
    }
    
    -(void)webViewDidFinishLoad:(UIWebView *)webView
    {
        //Stop or remove progressbar
    }
    
    -(void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
    {
        //Stop or remove progressbar and show error
    }
    
    0 讨论(0)
提交回复
热议问题