gpt4 book ai didi

ios - 如何打开从一个 UIWebView 到另一个 UIWebView 的链接?

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:42:48 26 4
gpt4 key购买 nike

我正在构建一个 iOS 应用。
我在带有超链接的 UIWebView 中有 HTML 内容,但我无法打开指向另一个 UIWebView 的链接。
我使用 UIWebView 作为 ViewController 的 subview 。这是代码:

- (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;
}
}
}

最佳答案

您只需要使用 Web View 转至一个新的 Controller ,并将请求传递给它。所以在你的第一个案例中是这样的,

 case UIWebViewNavigationTypeLinkClicked: { //this is when a user tap is detected
[self performSegueWithIdentifier:@"Next" sender:request];
isWebViewLoaded = false; //set this to false only if you open another view controller.
return NO; //prevent tapped URL from loading inside the UIWebView.
}

注意 performSegueWithIdentifier:sender: 中的 sender 参数是委托(delegate)方法返回的请求。将此请求传递给您要转到的 View Controller 中的属性,

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(NSURLRequest *)sender {
NextViewController *next = segue.destinationViewController;
next.request = sender;
}

最后,使用该请求在 NextViewController 中加载 WebView 。

关于ios - 如何打开从一个 UIWebView 到另一个 UIWebView 的链接?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24635107/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com