ios - 如何打开从一个 UIWebView 到另一个 UIWebView 的链接?
<p><p>我正在构建一个 iOS 应用。<br/>
我在带有超链接的 <code>UIWebView</code> 中有 HTML 内容,我无法打开指向另一个 <code>UIWebView</code> 的链接。<br/>
我使用 <code>UIWebView</code> 作为 <code>ViewController</code> 的 subview 。代码如下:</p>
<pre><code>- (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 viewcontroller.
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;
}
}
}
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>您只需要使用 WebView 连接到新 Controller ,并将请求传递给它。所以在你的第一种情况下是这样的,</p>
<pre><code> case UIWebViewNavigationTypeLinkClicked: { //this is when a user tap is detected
;
isWebViewLoaded = false; //set this to false only if you open another viewcontroller.
return NO; //prevent tapped URL from loading inside the UIWebView.
}
</code></pre>
<p>注意 performSegueWithIdentifier:sender: 中的 sender 参数是委托(delegate)方法返回的请求。将此请求传递给您要转到的 ViewController 中的属性,</p>
<pre><code>-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(NSURLRequest *)sender {
NextViewController *next = segue.destinationViewController;
next.request = sender;
}
</code></pre>
<p>最后,使用该请求在 NextViewController 中加载 WebView 。</p></p>
<p style="font-size: 20px;">关于ios - 如何打开从一个 UIWebView 到另一个 UIWebView 的链接?,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/24635107/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/24635107/
</a>
</p>
页:
[1]