Opening a new UIViewController when a link on a UIWebView is clicked

后端 未结 2 1458
长情又很酷
长情又很酷 2020-12-29 16:54

I found this thread which matches my problem: Clicking a link in UIWebView pushes onto the NavigationView stack

However, the following situations are different: Inst

相关标签:
2条回答
  • 2020-12-29 17:32

    I think you may use the shouldStartLoadWithRequest as Omar posted. If the new viewcontroller has a webviewcontroller, then you should pass the url (or even the request) to the new viewcontroller to show the clicked URL.

    0 讨论(0)
  • 2020-12-29 17:35

    You will have to do some modifications

    1st: when onClick, you will have to redirect your current page to a new location This location for example will be MYLocation://GoThere

    2nd: Update the shouldStartLoadWithRequest

    -(BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType {
    
    NSURL *url = request.URL;
    NSString *urlString = url.absoluteString;
    
    //Check if special link
    if ( [ urlString isEqualToString: @"MYLocation://GoThere" ] ) {
        //Here present the new view controller
        MyViewController *controller = [[MyViewController alloc] init];
        [self presentViewController:controller animated:YES];
    
        return NO;
    }
    
        return YES;
    
    }
    
    0 讨论(0)
提交回复
热议问题