Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
595 views
in Technique[技术] by (71.8m points)

ios - Show progress bar until it load the data in UIWebView IOS7

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 user that like its loading progress until it get load the my pdf once my file loaded its has hide the progress bar, how can I achieve this?

My webview code.

- (void)viewDidLoad
{
   [super viewDidLoad];

   NSString *pdf =@"http://jesusredeems.com/mag/pdf/JRE-2014-03.pdf";

   NSURL *url = [NSURL URLWithString:pdf];

   NSURLRequest *myRequest = [NSURLRequest requestWithURL:url];
   [webview loadRequest:myRequest];

}

I'm using the above code to load my pdf, how I can use the progress bar for file loading?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...