0

我正在UIWebView使用以下代码加载一个pdf文件:

NSString *path = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"%@", pdfString] ofType:@"pdf"];
NSURL *url = [NSURL fileURLWithPath:path];
NSURLRequest *req = [NSURLRequest requestWithURL:url];
[webview loadRequest:req];

它工作正常。但我想启用 pdf 文件中的超链接(就像如何UITextView检测链接一样)。

4

1 回答 1

1

用这个:

-(BOOL) webView:(UIWebView *)inWeb shouldStartLoadWithRequest:(NSURLRequest *)inRequest navigationType:(UIWebViewNavigationType)inType 
{
    if ( inType == UIWebViewNavigationTypeLinkClicked ) {
        [[UIApplication sharedApplication] openURL:[inRequest URL]];
        return NO;
    }
    return YES;
}
于 2013-02-11T09:18:47.990 回答