2016-08-26 42 views

回答

1

你可以这样做,

UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(20, 20, 200, 200)]; //whatever size you want 

NSURL *targetURL = [NSURL URLWithString:@"your url for pdf here"]; 
NSURLRequest *request = [NSURLRequest requestWithURL:targetURL]; 
[webView loadRequest:request]; 

[self.view addSubview:webView]; 
+0

我已经尝试过这一点,但它显示下载完成后的PDF。 –

+0

感谢您的回答。 –

+0

不客气... :) – Lion

1

为此,您可以尝试GCD

当您正在下载PDF,您可以显示webview.It预览并下载和同时显示预览。

对于这个GCD是一个很好的使用。

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{ 
    // Do the back ground process 
    ......Downloading the coding of pdf here 
    dispatch_async(dispatch_get_main_queue(), ^{ 
    // Update the UI here 
    .....Do the webview coding 
    }); 
}); 

全局队列

异步任务将在这里进行。 它不会等待。 异步函数不会阻止当前正在执行的线程继续执行下一个函数。

主队列

我们必须始终访问主线程UI套件类。

Ray wanderlich example

+0

我使用NSURLConnection方法下载pdf,假设我的pdf大小是10mb,并且最初我在didReceiveData方法中获得了2 MB数据,所以我想要显示带有大量数据的pdf。 –

+0

为什么你想在很多数据(MB大小)获得PDF? – user3182143

+0

它只是例如,我只是想下载PDF用户不会长时间卡在该屏幕上。 –