user304579
user304579

Reputation:

Detect if images have loaded in a UIWebView?

I have a UIWebview that is loading an image. However I am trying to call a method when the image has completed loaded / rendered.

I tried using UIWebViewDelgate and used,

-(void)webViewDidFinishLoad:(UIWebView *)webView {}

However this method is called before the image has loaded / rendered. How can I fix this. Any help would be greatly appreciated.

Josh

Upvotes: 4

Views: 1714

Answers (2)

sage444
sage444

Reputation: 5684

I think better way is use javascript to call any known url via window.location.href='myurl://imageLoaded' that will be intercepted in webView shouldStartLoadingRequest

there is way to set script for onload event Javascript that executes after page load

Upvotes: 1

Ortwin Gentz
Ortwin Gentz

Reputation: 54101

Unfortunately, the delegate call you mentioned, isn't called for each HTTP request but rather for each page only.

You should be able to get notified when a certain URL request is handled by subclassing NSURLProtocol. There's a related answer that describes how to substitute remote images with local images in a UIWebView. This should give you an idea how to implement your NSURLProtocol subclass.

Upvotes: 0

Related Questions