nik1004
nik1004

Reputation: 337

get urls of 2 uiwebview's and put to their own adress bar

In my app I have 2 UIWebView's and 2 Adress Bar tat called WebView and WebView2, webAdress and webAdress2. I need to get url from WebView and put it to webAdress, and from WebView2 and put it to webAdress2.

When I use this code, the URL updates appears only in first webAdress, url from WebView2 apperas in first webAdress too. Moreover, all pages from WebView2 starts to be load in WebView.

    - (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType {
        //CAPTURE USER LINK-CLICK.
        if (navigationType == UIWebViewNavigationTypeLinkClicked) {
            NSURL *URL = [request URL]; 
            if ([[URL scheme] isEqualToString:@"http"]) {
                [webAdress setText:[URL absoluteString]];
                [self gotoAddress:nil];
            }    
            return NO;
        }   
        return YES;   
    }

- (BOOL)webView2:(UIWebView*)webView2 shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType {
        //CAPTURE USER LINK-CLICK.
        if (navigationType == UIWebViewNavigationTypeLinkClicked) {
            NSURL *URL = [request URL]; 
            if ([[URL scheme] isEqualToString:@"http"]) {
                [webAdress2 setText:[URL absoluteString]];
                [self gotoAddress2:nil];
            }    
            return NO;
        }   
        return YES;   
    }

Upvotes: 0

Views: 572

Answers (1)

beryllium
beryllium

Reputation: 29767

I guess you are in need of only one delegate method. Check which webview has triggered this delegate method and perform actions depend on this:

- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType {
        //CAPTURE USER LINK-CLICK.
        if (navigationType == UIWebViewNavigationTypeLinkClicked) {
            NSURL *URL = [request URL]; 
            if ([[URL scheme] isEqualToString:@"http"]) {
                if (webView == webView1)
                     [webAdress setText:[URL absoluteString]];
                if (webView == webView2)
                     [webAdress2 setText:[URL absoluteString]];
                [self gotoAddress2:nil];
            }    
            return NO;
        }   
        return YES;   
    }

Just set for all web views delegate as self, and all you can handle all actions in this method.

Upvotes: 2

Related Questions