I'm creating an iOS app.
I separated a PDF which has multi page into each pages,
And then create UIWebViews to show each pages.
The code is like this.
for( int i = 0; i < _pageNumbers; i++)
{
_webView = [[UIWebView alloc]init];
_webView.delegate = self;
_webView.frame = imageViewFrame;
_webView.scalesPageToFit = YES;
_webView.autoresizingMask =
UIViewAutoresizingFlexibleLeftMargin |
UIViewAutoresizingFlexibleWidth |
UIViewAutoresizingFlexibleRightMargin |
UIViewAutoresizingFlexibleTopMargin |
UIViewAutoresizingFlexibleHeight |
UIViewAutoresizingFlexibleBottomMargin;
[self setImageAtIndex:i toScrollView:imageScrollView];
}
- (void)setImageAtIndex:(NSInteger)index toScrollView:(ImageScrollView*)ScrollView
{
UIWebView *theWebView = (ScrollView.subviews)[0];
if (index < 0 || [webViews count] <= index) {
theWebView = nil;
return;
}
dispatch_queue_t queueLoadPDF = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_sync(queueLoadPDF, ^{
NSString *document = [[[[NSString alloc]initWithString:_documwntPath]stringByAppendingString:@"/"]stringByAppendingFormat:@"Page%zd.pdf",(index + 1) ];
NSURL *url = [NSURL fileURLWithPath:document];
NSString *urlString = [url absoluteString];
NSString *encodedString=[urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *webURL = [NSURL URLWithString:encodedString];
NSURLRequest *req = [NSURLRequest requestWithURL:webURL];
[theWebView loadRequest:req];
});
}
The PDF pages are big. After calling loadRequest, program go back to the loop and creates new UIWebview.
I want to wait until webViewDidFinishLoad is called before returning to the loop.
Is there any solutions?
Thank you for your helps.