点击链接时有关UIWebview的问题

时间:2011-06-17 18:47:23

标签: ios xcode cocoa-touch uiwebview

我有一个加载html文件的UIWebView。用户点击链接后,我希望在自定义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方法

中完成的

1 个答案:

答案 0 :(得分:2)

不应该这样吗?

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

        return NO;
    }

    return YES;
}