【问题标题】:How to detect the hyperlinks in a local pdf displayed in a UIWebView如何检测 UIWebView 中显示的本地 pdf 中的超链接
【发布时间】:2013-02-11 09:13:30
【问题描述】:

我正在使用以下代码在 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 检测链接的方式一样)。

【问题讨论】:

标签: ios objective-c uiwebview datadetectortypes


【解决方案1】:

使用这个:

-(BOOL) webView:(UIWebView *)inWeb shouldStartLoadWithRequest:(NSURLRequest *)inRequest navigationType:(UIWebViewNavigationType)inType 
{
    if ( inType == UIWebViewNavigationTypeLinkClicked ) {
        [[UIApplication sharedApplication] openURL:[inRequest URL]];
        return NO;
    }
    return YES;
}

【讨论】:

    猜你喜欢
    • 2014-06-09
    • 2016-01-20
    • 2012-03-22
    • 1970-01-01
    • 2011-11-15
    • 1970-01-01
    • 2011-12-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多