Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIWebView is loading very slowly on the first time it is displayed in a specific UIViewController

I have a "product details" UIViewController on my storyboard which has a UIWebView to display "rich text" (basically bold and italic). The web view is loaded using a string (fetched from CoreData) loadHTMLString. The problem is that the first time the view is displayed, there is at least a one second delay before the web view is rendered. Further "product details" views that are loaded all load fine. It is only the first "product details" web view which takes the time to load.

This is what I have tried (with no joy)

  1. Displaying a UIWebView with text on the first screen (to warm up the UIWebView)
  2. When it comes time to show the details view, init the web view in the prepare for segue method and pass it to the "product details" view controller.
  3. I have tried various combinations of having the web view in the storyboard / not in the storyboard / in a scroll view etc

I would be very interested if others have had this problem and how they got over it / worked around it. I find it strange I have not been able to find many similar problems on SO; I must be doing something stupid...


Note, I am using a UIWebView so I can display rich text. I understand I can display rich text using other controls, but the program that makes the text that I want to display can only export rich text using HTML.

like image 761
lindon fox Avatar asked Apr 06 '13 03:04

lindon fox


2 Answers

This is a common problem for UIWebView. My workaround is to make the web view initially hidden (showing some sort of "Loading..." indicator instead), then make it un-hidden in the webViewDidFinishLoad: method.

like image 180
MusiGenesis Avatar answered Oct 25 '22 17:10

MusiGenesis


Instead of use an UIWebView to display rich text content, you can try use OHASBasicHTMLParser of OHAttributedLabel which is backwards compatible with versions prior to iOS 6.

You can find an example of its markup parsers here.

like image 34
ararog Avatar answered Oct 25 '22 16:10

ararog