显示进度条,直到它加载UIWebView IOS7中的数据
嗨在我的应用程序,我有UIWebView
加载pdf
文件使用URL它非常大的文件它需要太多的时间来加载。 现在我想显示用户喜欢它的加载进度,直到它得到加载我的PDF一旦我的文件加载它有隐藏进度条,我怎么能做到这一点?
我的webview代码。
- (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]; }
我正在使用上面的代码来加载我的pdf
,我怎么可以使用进度条进行文件加载?
您应该开始/停止webview委托方法中的进度条。
在viewDidLoad
添加以下行。
webview.delegate = self;
在您的控制器中添加以下function…
-(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 }
是的,为什么不使用UIWebView
委托方法
- (void)viewDidLoad { [super viewDidLoad]; webview.delegate=self; //Assign Delegate [webview loadRequest:myRequest]; [self showProgress];//Show Progress }
使用代表如下
- (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]; }
干杯。