mstottrop
mstottrop

Reputation: 589

Question about UIWebview when tapping links

I have an UIWebView which loads an html-file. Once the user clicks a link, i want the url to open in a custom UIWebview. I tried some things:

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];   
}

This is me, loading the files, depending on the device. That works great. I did it in the - (void)viewDidLoadmethod

Upvotes: 0

Views: 277

Answers (1)

Deepak Danduprolu
Deepak Danduprolu

Reputation: 44633

Shouldn't this work?

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

        return NO;
    }

    return YES;
}

Upvotes: 2

Related Questions