嗨,在我的应用程序中,我有UIWebView,它使用URL加载pdf文件,它非常大的文件需要花费太多的时间来加载。现在,我想向用户展示喜欢它的加载进度,直到它得到加载my,一旦我的文件加载了它的进度条隐藏,我如何才能做到这一点?
我的网页代码。
- (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,如何使用进度条加载文件?
发布于 2014-05-31 05:33:45
您应该在webview委托方法中启动/停止进度条。
在viewDidLoad中添加以下行。
webview.delegate = self;在控制器中添加以下功能..。
-(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
}发布于 2014-05-31 05:36:06
是的,为什么不,使用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];
}干杯。
https://stackoverflow.com/questions/23966697
复制相似问题