点击链接时关于UIWebview的问题

Posted

技术标签:

【中文标题】点击链接时关于UIWebview的问题【英文标题】:Question about UIWebview when tapping links 【发布时间】:2011-06-17 18:47:22 【问题描述】:

我有一个加载 html 文件的 UIWebView。一旦用户单击链接,我希望 url 在自定义 UIWebview 中打开。 我尝试了一些东西:

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) 
    NSString *htmlPath = [[NSBundle mainBundle] pathForResource:@"MyiPadHTML"
                                                         ofType:@"html"];
    NSURL *url = [NSURL fileURLWithPath:htmlPath];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    [webview loadRequest:request];       


else  
    NSString *htmlPath = [[NSBundle mainBundle] pathForResource:@"MyHTML" 
                                                         ofType:@"html"];
    NSURL *url = [NSURL fileURLWithPath:htmlPath];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    [webview loadRequest:request];   

这是我,根据设备加载文件。这很好用。我在- (void)viewDidLoad方法中做到了

【问题讨论】:

您的意思是您希望它加载到不同的UIWebView 对象中? 是的。在不同的自定义 UIWebview 中。 【参考方案1】:

这不应该工作吗?

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType 
    if ( navigationType == UIWebViewNavigationTypeLinkClicked ) 
        [myOtherCustomWebView loadRequest:request];

        return NO;
    

    return YES;

【讨论】:

哦,不,你不是我忘了检查OK。再次感谢您的帮助:)

以上是关于点击链接时关于UIWebview的问题的主要内容,如果未能解决你的问题,请参考以下文章