Loading the content of a UIWebView before displaying it

孤街醉人 提交于 2019-12-22 05:18:09

问题


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).

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.

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.

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?


回答1:


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:

In viewWillAppear: I unhide the loading view and start the spinner.

In webViewDidFinishLoad I hide the loading view.

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.

If you're curious, you can see this in the high score page of my game (Lexitect, free)



来源:https://stackoverflow.com/questions/2973237/loading-the-content-of-a-uiwebview-before-displaying-it

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!