• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

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

[复制链接]
菜鸟教程小白 发表于 2022-12-13 08:25:28 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

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

- (BOOL)webViewUIWebView *)webView shouldStartLoadWithRequestNSURLRequest *)request navigationTypeUIWebViewNavigationType)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;
        } 
    }
} 



Best Answer-推荐答案


您只需要使用 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)prepareForSegueUIStoryboardSegue *)segue senderNSURLRequest *)sender {
    NextViewController *next = segue.destinationViewController;
    next.request = sender;
}

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

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

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap