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

查看:929
本文介绍了在尚未显示的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 并且你的 SecondViewController 中有你的webView把 loadHTMLString 或<你的 SecondViewController viewDidLoad 中的code> loadRequest 方法并调用 [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.

Ex:

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天全站免登陆