4

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

Ortwin Gentz
  • 52,648
  • 24
  • 135
  • 213

2 Answers2

1

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

Community
  • 1
  • 1
sage444
  • 5,661
  • 4
  • 33
  • 60
0

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.

Community
  • 1
  • 1
Ortwin Gentz
  • 52,648
  • 24
  • 135
  • 213