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?
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?
Load webview in dispatch thread, try this:
dispatch_async(dispatch_get_main_queue(), ^{
[self.webView loadHTMLString:@"htmlstring" baseURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]]];
});
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)
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
...
}
}