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

时光毁灭记忆、已成空白 提交于 2019-11-30 05:31:16

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;

}

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!