iPhone UIWebView - 从超链接打开新的UIWebView控制器

use*_*696 4 iphone

我有一个嵌入式网站有很多链接,但webview窗口相当小,以允许放大和缩小列表上方的大图像.我需要webview响应超链接到新的控制器视图,如果可能的话,使用第二个嵌入式UIWebView.

Phl*_*bbo 13

UIWebView有一个委托,允许您响应某些事件,例如加载新内容的请求.只需在您的委托类中实现以下内容即可

-(bool) webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
    //You might need to set up a interceptLinks-Bool since you don't want to intercept the initial loading of the content
    if (self.interceptLinks) {
        NSURL *url = request.URL;
        //This launches your custom ViewController, replace it with your initialization-code
        [YourBrowserViewController openBrowserWithUrl:url];     
        return NO;
    }
    //No need to intercept the initial request to fill the WebView
    else {
        self.interceptLinks = YES;
        return YES;
    }
}
Run Code Online (Sandbox Code Playgroud)