-1

I am Loading HTML String in UIWebView,text content get loaded in a sec but there is lot of images in HTML String, cause of this image my UIWebView get freeze, after loaded all images my screen get free to use.

Any Suggestion on this?

Bhavin Ramani
  • 3,221
  • 5
  • 30
  • 41
Nikunj Suthar
  • 39
  • 1
  • 4

3 Answers3

1

Load webview in dispatch thread, try this:

dispatch_async(dispatch_get_main_queue(), ^{
    [self.webView loadHTMLString:@"htmlstring" baseURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]]];
});
Borys Verebskyi
  • 4,160
  • 6
  • 28
  • 42
Satyanarayana
  • 1,059
  • 6
  • 16
0

I think it's freezing because you're loading a images from web in your main thread, Which is also responsible for redrawing your UI. By loading a large images inside your thread, your UI freezes as well.

I would recommend moving the code that does images loading into a separate thread. (you can use @Andey's answer)

Suraj Sukale
  • 1,778
  • 1
  • 12
  • 19
  • I tried andey's solution but still getting issue, the problems is in the images because if i disconnect the net then string get loaded into UIWebview and screen not get freeze. – Nikunj Suthar Jun 22 '16 at 11:39
  • you're loading a images from web in your main thread.try to do into a separate thread. – Suraj Sukale Jun 22 '16 at 11:59
0

Like @Andey said, you should dispatch off the main queue whenever the thing you're doing will take some time and you don't want your view to freeze.

Try lecture 9: https://itunes.apple.com/en/course/developing-ios-8-apps-swift/id961180099


UPDATE (Swift ver.):

Although I do not know how to write this in Obj-C, it will look something like this in Swift, which you can later translate it back to Obj-c.

dispatch_async(notTheMainQueue) {
    // Some time consuming stuff you're doing (downloading data, calculating..)
    ...
    dispatch_async(dispatch_get_main_queue) {
        // Set your view here, which dispatches *back* to the main queue and will not block your UI
        ...
    }
}
Ray Tso
  • 566
  • 9
  • 17