我有两个 UIWebView,一个用于处理普通文件,一个用于处理 PDF(作为覆盖打开,位于另一个 Web 视图之上)。
两个 webview 的设置如下:
//Options for webView
webView.delegate = self;
webView.scalesPageToFit = YES;
for (id subview in webView.subviews)
if ([[subview class] isSubclassOfClass: [UIScrollView class]])
((UIScrollView *)subview).bounces = NO;
//Options for pdfViewer
pdfViewer.delegate = self;
pdfViewer.scalesPageToFit = YES;
for (id subview in pdfViewer.subviews)
if ([[subview class] isSubclassOfClass: [UIScrollView class]])
((UIScrollView *)subview).bounces = NO;
该行pdfViewer.delegate = self;
给我的应用程序带来了一些麻烦。我有一个我正在使用的委托方法webViewDidFinishLoad
,所以我需要delegate
两个视图的self
. 如果未设置,即我将其注释掉。PDF 在视图中加载,但webViewDidFinishLoad
不会触发,如您所料。但是,如果我重新激活该行,PDF 根本不会加载到视图中。是否发生了某种冲突?我可以分配多个UIWebViews
delegate = self
吗?
更新:
#import "MyViewController.h"
@implementation MyViewController
@synthesize webView;
//these two just appear to show the page is loading.
@synthesize loadingView;
@synthesize linkLoadView;
//pdfViewer is contained within topView
@synthesize topView;
@synthesize pdfViewer;
- (void)viewDidLoad {
[super viewDidLoad];
linkLoadView.alpha=0.0;
[topView removeFromSuperview];
//Options for
webView.delegate = self;
webView.scalesPageToFit = YES;
for (id subview in webView.subviews)
if ([[subview class] isSubclassOfClass: [UIScrollView class]])
((UIScrollView *)subview).bounces = NO;
//Options for
//pdfViewer.delegate = self;
pdfViewer.scalesPageToFit = YES;
for (id subview in pdfViewer.subviews)
if ([[subview class] isSubclassOfClass: [UIScrollView class]])
((UIScrollView *)subview).bounces = NO;
NSURL *filePath = [NSURL URLWithString:@"*webaddress*/index.html"];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:filePath];
[webView loadRequest:requestObj];
}
- (BOOL) webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType; {
/* Add Content Loading Banner */
if (navigationType == UIWebViewNavigationTypeLinkClicked) {
[self.view addSubview:linkLoadView];
linkLoadView.alpha = 1.0;
}
/* Handle PDF Opening */
NSURL *url = [request URL];
NSString *urlString = [url absoluteString];
if([urlString rangeOfString:@".pdf"].location == NSNotFound){
return true;
} else {
NSURL *filePath = [NSURL URLWithString:urlString];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:filePath];
[pdfViewer loadRequest:requestObj];
[self.view addSubview:topView];
[self.view addSubview:linkLoadView];
return false;
}
}
- (void) webViewDidFinishLoad:(UIWebView *)theWebView{
NSLog(@"Fired");
}
@end