UIWebView 加载本地内容的延迟 [英] UIWebView delay in loading local content

查看:22
本文介绍了UIWebView 加载本地内容的延迟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 UIWebView 中显示了少量本地内容,大约 3 段文本和一个 100x100 像素的图像.当 UIWebView 被推送到导航控制器上时,大约需要半秒才能显示内容.这发生在设备上,而不是在模拟器中.显然 UIWebView 需要在显示内容之前做一些工作,但是在推送视图出现之前我有什么方法可以做到这一点吗?我自己没有运气.

I'm displayed a small amount of local content in a UIWebView, roughly 3 paragraphs of text and one 100x100px image. When the UIWebView is pushed onto to the nav controller, it takes about half a second before the content is displayed. This occurs on the device, not in the simulator. Obviously the UIWebView needs to do some work before displaying the content, but is there some way I can do this before the pushed view appears? I have not had any luck doing this myself.

这里是我创建和推送包含 UIWebView 的视图控制器的地方:

Here is where I'm creating and pushing the view controller which contains the UIWebView:

ArticleViewController* viewController = [[ArticleViewController alloc] init];
viewController.article = article;
[viewController view]; //touch the view so it gets loaded
[viewController loadWebView]; //load the web view content
[self.navigationController pushViewController:viewController animated:YES];
[viewController release];

这里是 loadWebView 方法:

-(void)loadWebView {
    NSString *path = [[NSBundle mainBundle] bundlePath];
    NSURL *baseURL = [NSURL fileURLWithPath:path];

    NSString* content = article.content;

    NSString *html = [NSString stringWithFormat:@"
                      <html><body style='background-color: transparent'><style type=""text/css"">body {font-family: helvetica; color: black; font-size: 10pt; margin: 10px 10px 10px 10px}</style>
                      %@<div style='text-align:center'><a href='13443574_9709e4cf37.jpg?photographer=test' style='-webkit-tap-highlight-color:rgba(0,0,0,0);'><img src='13443574_9709e4cf37.jpg' height='160' width='230'></a></div></body></html>", content];
    [self.webView loadHTMLString:html baseURL:baseURL];
}

之前我在viewDidLoad方法中有[viewController loadWebView],但是结果好像是一样的.推送 viewController 时出现空白屏幕,然后在半秒后加载内容.

Previously I had [viewController loadWebView] in the viewDidLoad method, but the result seems to be the same. A blank screen when the viewController is pushed, followed by the content loading half a second later.

有什么想法吗?

推荐答案

你要让用户等待,唯一的问题是:是在webview出现之前还是之后?如果您设置为之前",那么您应该创建控制器,加载 Web 视图,但等待推送它,直到 -webViewDidFinishLoad: 委托方法触发.收到后,您可以推送视图.

You're going to make the user wait, the only question is: is it before or after the webview appears? If you're set on "before", then you should create the controller, load the web view, but wait to push it until the -webViewDidFinishLoad: delegate method fires. Once you receive that, you can push the view.

这篇关于UIWebView 加载本地内容的延迟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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