Note that there are some explanatory texts on larger screens.

plurals
  1. PODelay in loading a HTML string into a UIWebView
    text
    copied!<p>I have two view controllers inside a navigation controller. The 1st view controller has a menu with a button. Pressing this button moves to the 2nd view controller and loads a html string into a UIWebView. Nothing else is being loaded to the webview, just a simple NSString with html code in it. Essentially I'm making a flip card (two views) with the webview as a subview of one of the uiviews.</p> <p>Here's the code:</p> <pre><code>containerView = [[UIView alloc] initWithFrame:CGRectMake(20, 20, 280, 280)]; [self.view addSubview:containerView]; frontView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 280, 280)]; frontView.layer.cornerRadius = 10; frontView.layer.masksToBounds = YES; [frontView setBackgroundColor:[UIColor whiteColor]]; backView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 280, 280)]; backView.layer.cornerRadius = 10; backView.layer.masksToBounds = YES; [backView setBackgroundColor:[UIColor yellowColor]]; [containerView addSubview:frontView]; webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 280, 280)]; webView.scalesPageToFit = YES; webView.userInteractionEnabled = NO; NSString *htmlString = @"&lt;head&gt;&lt;meta name='viewport' content='width=device-width;'&gt;&lt;style type='text/css'&gt;html,body {margin: 0;padding: 0;width: 100%;height: 100%;}html {display: table;}body {display: table-cell;vertical-align: middle;padding: 20px;text-align: center;-webkit-text-size-adjust: none;}&lt;/style&gt;&lt;/head&gt;&lt;ruby&gt;金&lt;rt&gt;きん&lt;/rt&gt;&lt;/ruby&gt;&lt;ruby&gt;曜&lt;rt&gt;よう&lt;/rt&gt;&lt;/ruby&gt;&lt;ruby&gt;日&lt;rt&gt;び&lt;/rt&gt;&lt;/ruby&gt;"; [webView loadHTMLString:htmlString baseURL:nil]; [frontView addSubview:webView]; UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(flip)]; [self.view addGestureRecognizer:tap]; </code></pre> <p>} </p> <p>Issue: I notice that on the first time I press the button to transition to the second view controller that there is a delay in seeing the html string loaded to the webview (it's only about 0.5 - 1 second). This doesn't happen if I go back to the first view controller and hit the button again - this time it's instant.</p> <p>Any ideas what might be causing this first time delay and how to avoid it?</p> <p>Thanks</p>
 

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