Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Answer extension for documentation purposes to maybe help someone else:</p> <p>I had the same desire (clear content before loading next url) but had a UIWebView delegate set to receive <code>webviewDidFinishLoad:(UIWebView)webview</code> message and update another part of UI in response. </p> <p>Problem: the call to clear the content to <em>also</em> called delegate method, so getting false-hits (that is, getting call when clear is done, too, but delegate is coded to expect call only when real content is loaded).</p> <p>Solution: use a known URL for clear, and have <code>webviewDidFinishLoad:</code> ignore calls made when that URL is finished:</p> <pre><code>- (void) startLoadOfNextURL:(NSURL*)url { // clear: [self.webView loadHTMLString:@"" baseURL:nil]; // Load real next URL NSURLRequest* request = [NSURLRequest requestWithURL:url]; [self.webView loadRequest:request]; } - (void)webViewDidFinishLoad:(UIWebView *)webView { NSLog(@"WebView finished loading: %@", webView); if ([self.webView.request.URL.absoluteString isEqualToString:@"about:blank"]) { NSLog(@" This is Blank. Ignoring as false event."); } else { NSLog(@" This is a real url"); [self updateUIInSomeWay]; } } </code></pre> <p>Note: using this:</p> <pre><code> [self.webView loadHTMLString:@"about:blank" baseURL:nil]; </code></pre> <p>actually causes the words "about:blank" to appear as text in the webview's content pane!</p> <p>Final complication: In practice, with my two <code>[webview load...]</code> calls so close together, I was finding that instead of a "loaded" event for the clear, the webview was actually canceling it in favor of the second request and calling <code>webView: didFailLoadWithError:</code> for the first load request. Thus, I had to put similar code in that event:</p> <pre><code>- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error { NSLog(@"WebView error on: %@", webView); NSLog(@"Error is: %@", error); NSURL* failingURL = [error.userInfo objectForKey:@"NSErrorFailingURLKey"]; if ([failingURL.absoluteString isEqualToString:@"about:blank"]) { NSLog(@" This is Blank. Ignoring."); } else { NSLog(@" This is a real URL."); [self doSomethingAboutError]; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload