开发者

open UIViewController from webView

开发者 https://www.devze.com 2023-04-04 18:35 出处:网络
I have an app which adds a webview as a subview of the main UIViewController. I want to intercept the links clicked in this webview and open them in a new UIViewController (as modal view or navigation

I have an app which adds a webview as a subview of the main UIViewController. I want to intercept the links clicked in this webview and open them in a new UIViewController (as modal view or navigationController). For this new UIViewController, i am using https://github.com/samvermette/SVWebViewController which is an inline browser class and works pretty well.

I am able to intercept clicks from that webview just fine in webView:shouldStartLoadWithRequest:navigationTy开发者_高级运维pe. But my problem is that it is not able to open the new UIViewController (SVWebViewController). Following is the code to intercept clicks in the webView and open it :

- (BOOL) webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest    *)inRequest navigationType:(UIWebViewNavigationType)inType {

  if(inType == UIWebViewNavigationTypeLinkClicked) {

    NSURL *url = [inRequest URL];

    NSString *fname = [url absoluteString];

    SVWebViewController *webViewController = [[SVWebViewController alloc]  initWithAddress:fname];

    [self presentModalViewController:webViewController animated:YES];

    [webViewController release];

    return NO;

  }

  return YES;

}

There is no issue in SVWebViewController, it works fine when i call it from the main UIView but not when i use it to open clicks from the webView.

Thanks for your help!!

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号