【发布时间】:2014-07-08 14:56:32
【问题描述】:
我正在构建一个 iOS 应用程序。
我在 UIWebView 中有带有超链接的 HTML 内容,但我无法打开指向另一个 UIWebView 的链接。
我使用UIWebView 作为ViewController 的子视图。代码如下:
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
switch (navigationType) {
case UIWebViewNavigationTypeLinkClicked: { //this is when a user tap is detected
//write the handling code here.
isWebViewLoaded = false; //set this to false only if you open another view controller.
return NO; //prevent tapped URL from loading inside the UIWebView.
}
// some other typical parameters within a UIWebView. Use what is needed
case UIWebViewNavigationTypeFormResubmitted: return YES;
case UIWebViewNavigationTypeReload: return YES;
//for all other cases, including UIWebViewNavigationTypeOther called when UIWebView is loading for the first time
default: {
if (!isWebViewLoaded) {
isWebViewLoaded = true;
return YES;
}
else
return NO;
}
}
}
【问题讨论】:
-
那么你是说要在单独的 UIWebView 中打开链接?
-
似乎您的代码来自:cloudfields.net/blog/uiwebview-link-interceptor,无论如何,一旦您拦截了为什么不能简单地使用被捕获的 URL 打开一个新的 uiwebview ? - 你有所有的信息
-
如果您解释为什么需要这样做,我们将能够为您提供更好的帮助。
-
嗨,克里斯,谢谢!,由于是 iOS 开发的新手,我不知道如何使用此代码来满足我的要求。
-
上面的代码不起作用,链接是可点击的,但没有任何事件,我想要当用户点击链接并且它在新的 UIWebView 中打开并带有返回按钮。
标签: ios objective-c webview uiscrollview