在尚未显示的 UIViewController 上预加载 UIWebView [英] PreLoad UIWebView on a not yet displayed UIViewController

查看:39
本文介绍了在尚未显示的 UIViewController 上预加载 UIWebView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,在最后一个 UIViewController 上有一个 UIWebView... 用户浏览应用程序,最后他们可以转换(模态)到带有 UIWebView 的最终 UIViewController... 在它的 viewDidLoad我让 UIWebView 加载页面.

I have an app where on the very last UIViewController there is a UIWebView... the user navigates through the app and at the very end they can transition (modal) to the final UIViewController with a UIWebView... in it's viewDidLoad I have the UIWebView load the page.

问题是加载这个页面需要大约 8 秒,这让用户很恼火.

The problem is it takes about 8 seconds to load this page and that annoys users.

如果 UIViewController 尚未呈现,我该如何提前加载 UIWebView(例如应用程序首次启动时!)?

How can I load the UIWebView way ahead of time (like when the app is first launched!) if that UIViewController hasn't even been presented yet?

推荐答案

我在 UIPageViewController 中遇到了与 UIWebView 相同的问题,我找到了更好的解决方案.

I had your same problem for UIWebView inside a UIPageViewController and I found a better solution.

如果你在 FirstViewController 并且你的 webView 在你的 SecondViewControllerloadHTMLStringloadRequest 方法在您的 SecondViewControllerviewDidLoad 中,并调用 [secondViewController.view layoutSubviews] 开始在您的 FirstViewController 中加载.

If you are in FirstViewController and you have your webView in your SecondViewController put the loadHTMLString or loadRequest method in the viewDidLoad of your SecondViewController and call [secondViewController.view layoutSubviews] for start loading in your FirstViewController.

例如:

FirstViewController

-(void)viewDidLoad{
    [super viewDidLoad];
    // _secondViewController -> An instance of SecondVieController
    [_secondViewController.view layoutSubviews];
}

SecondViewController

-(void)viewDidLoad{
    [super viewDidLoad];
    NSURL *url =[NSURL URLWithString:@"http://www.google.it"];
    NSURLRequest *request =[NSURLRequest requestWithURL:url];
    [self.webView loadRequest:request];
}

这篇关于在尚未显示的 UIViewController 上预加载 UIWebView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆