0

I'm using a UIWebView to render local html content (special html content with javascript). The html content needs to get incrementally updated often, but every time that happens and I reload the web view, it does a little "dance" to refresh, which is very distracting, especially since the updates are very minor and happen often. If I could just freeze the display, reload the page behind the scenes, and then repaint the display, I'm sure that would look fine. But, can I do that? Or are there any other approaches to refresh an html page (or just some of the content of the page) seamlessly?

Thank you in advance for the help!

rmp251
  • 5,018
  • 4
  • 34
  • 46

1 Answers1

1

You could:

  1. take a "screenshot" of the UIWebView, (see How to capture current view screenshot and reuse in code? (iPhone SDK));
  2. display it in a UIImageView over the UIWebView;
  3. reload the UIWebView;
  4. when the UIWebView has finished reloading, remove the UIImageView from the view hierarchy.

I doubt there is a way to tell the UIWebView to "freeze" the display while reloading as the Webkit rendering provides a feedback to the user about the page loading state.

Another solution would be to update the DOM with javascript (and XHR presumably), removing the need to reload the whole page in the UIWebView.

Community
  • 1
  • 1
Guillaume Algis
  • 10,705
  • 6
  • 44
  • 72
  • Thanks for the response. First option seems a little too convoluted. Would you mind elaborating on the second solution? (not familiar with XHR) – rmp251 Aug 21 '13 at 20:07
  • The first option really shouldn't be must of a hassle. The javascript solution is to use Ajax to reload parts of the HTML code without reloading the whole page. If you are using jQuery, there is [a bunch of function to take care of it](http://api.jquery.com/category/ajax/). If you never done something like this, google "Ajax", there is lot of tutorials out there :) – Guillaume Algis Aug 21 '13 at 20:17
  • Finally got it all working using JavaScript. I ended up having to synchronize my javascript and objective-C code. Summary: 1. Used `stringByEvaluatingJavaScriptFromString` to invoke javascript from objective-C. 2. Used [this approach](http://blog.techno-barje.fr/post/2010/10/06/UIWebView-secrets-part3-How-to-properly-call-ObjectiveC-from-Javascript/) to signal to objective-C when javascript was complete. Works great now. – rmp251 Aug 24 '13 at 03:11