在显示之前加载UIWebView的内容 [英] Loading the content of a UIWebView before displaying it
问题描述
我的应用中有一定数量的ViewControllers。它们在应用程序启动时分配和初始化,并在退出时释放。它们由NavigationController用于推送/弹出。在这些ViewControllers中有WebViews(实际上没有别的东西)。
I have a set number of ViewControllers in my app. They are allocated and initialized at application launch and released at exit. They are used by a NavigationController to be pushed/popped. In these ViewControllers there are WebViews (actually there is nothing else).
我的问题是:
当我想要更改WebView的内容(URL)时这不是在当前的TopViewController上,直到我按下/弹出相关的ViewController才会加载内容。
My problem is : When I want to change de content (URL) of a WebView that is not on the current TopViewController, the content isn't loaded until I push/pop the associated ViewController.
过渡我们丑陋。推送/弹出的Viewcontroller最好显示旧内容或最好的空白页面,然后ViewController在完整视图中显示新内容。
And the transition us "ugly". The pushed/popped Viewcontroller shows old content at worst or blank page at best, before the ViewController is in full view THEN the new content is shown.
我尝试了很多东西(甚至将loadRequest放在一个看起来很愚蠢的不同线程中)。
I tried lots of things (even putting the "loadRequest" in a different thread with looks stupid).
你知道如何让事情顺利进行吗?
Do you know any way to make things go smooth?
推荐答案
一般情况下,您应该为缓慢的UIWebView负载规划UI,因为您无法提前计划知道需要多长时间。我经常做的是有一个UIView,它有一个微调器和一个消息,例如Loading ...,它位于UIWebView之上。以下是我如何使用它:
In general you should plan your UI for slow UIWebView loads, because you can't plan ahead to know how long things will take. What I often do is have a UIView that has a spinner and a message such as "Loading..." that is layered on top of the UIWebView. Here's how I use it:
在viewWillAppear中:我取消隐藏加载视图并启动微调器。
In viewWillAppear: I unhide the loading view and start the spinner.
In webViewDidFinishLoad我隐藏了加载视图。
In webViewDidFinishLoad I hide the loading view.
如果调用了webViewDidFail,那么在页面加载时你不会显示一些临时或无效的内容。你可以在这种情况下展示UIAlertView。
If webViewDidFail gets called, then you're not showing some interim or invalid content while the page loads. You can present a UIAlertView in that case.
如果你很好奇,你可以在我的游戏的高分页面看到这个(Lexitect,免费)
If you're curious, you can see this in the high score page of my game (Lexitect, free)
这篇关于在显示之前加载UIWebView的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!