In my app, I need a way to tell when my webview is finished loading. It is very easy to do that if content is html. However, my content source is javascript with iFrame inside, it will cause UIWebView finishedLoad method called several times. Is there anyway I can check to see if the iframe is finished loading?
相关问题
- Is there a limit to how many levels you can nest i
- How to toggle on Order in ReactJS
- void before promise syntax
- Keeping track of variable instances
- CALayer - backgroundColor flipped?
To tell if a webview is loading, you can use
webView.isLoading
to check if all the frames of a webview are done loading. No counting the number of iframes necessary. Simply check ifisLoading
is true insidewebViewDidFinishLoad:
http://developer.apple.com/library/ios/#documentation/uikit/reference/UIWebView_Class/Reference/Reference.html
(If it is the same domain) you can call a function (in the parent) from the iframe.
The only foolproof method I've found is to listen to the three methods that say it's about to start loading, and that it finished loading (plus equivalent for "failed"), and to manually maintain a count for each.
i.e. something like:
I've also usually had to overrid the didFail method - Apple incorrectly uses this to report that e.g. the YouTube player has taken over the handling of a YouTube video. It's NOT a fail, it's a "page was loaded by a different application".
e.g.