SVModalWebViewController - 从UIWebView传递URL

时间:2017-02-13 13:55:13

标签: ios objective-c uiwebview

我有一个主UIWebView,我试图使用SVWebViewController打开任何URL。我的代码可以在下面看到。

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
    if (navigationType == UIWebViewNavigationTypeLinkClicked ) {
        SVModalWebViewController *webViewController = [[SVModalWebViewController alloc] initWithAddress:@"http://google.com"];
        [self presentViewController:webViewController animated:YES completion:NULL];
        return NO;
    }

    return YES;
}

看起来SVWebViewController有一个initWithAddress参数。我想知道我是否可以在该参数中传递请求的URL。

提前谢谢。

1 个答案:

答案 0 :(得分:0)

找到了解决这个问题的方法。好像我可以使用

initWithURLRequest:(NSURLRequest *)请求

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
    if (navigationType == UIWebViewNavigationTypeLinkClicked ) {
        SVModalWebViewController *webViewController = [[SVModalWebViewController alloc] initWithURLRequest:(NSURLRequest *)request];
        [self presentViewController:webViewController animated:YES completion:NULL];
        return NO;
    }

    return YES;
}