我有两个UIWebViews,一个用于处理普通文件,另一个用于处理PDF(在另一个Web视图的顶部以叠加方式打开)。
两个网页浏览设置如下:
//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
答案 0 :(得分:1)
您是否覆盖了UIWebView委托中的任何其他方法,例如shouldLoadRequest等....?
将单个委托给多个webview没有任何问题所以我猜测某些东西正在某个地方停止正常的请求过程。