Note that there are some explanatory texts on larger screens.

plurals
  1. POYouTube UITableView cells using UIWebView blocking thread?
    text
    copied!<p>I have a <code>UITableView</code> which displays YouTube data such as video title and date. I am also displaying a <code>UIWebView</code>(75x75px) for each <code>UITableViewCell</code> which loads an HTML string.</p> <p>here is the pertinent code for <code>- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath</code>:</p> <pre><code>UIWebView *iconView = (UIWebView*)[cell.contentView viewWithTag:2]; [self embedYouTube:videoUrl frame:CGRectMake(0, 0, 75, 75) webView:iconView]; </code></pre> <p>and the <code>embedYouTube</code> function:</p> <pre><code>- (void)embedYouTube:(NSString*)url frame:(CGRect)frame webView:(UIWebView*)webView { if([loadedIconsArray containsObject:webView]) return; NSString *youTubeVideoHTML = @"&lt;html&gt;&lt;head&gt;\ &lt;body style=\"margin:0\"&gt;\ &lt;embed id=\"yt\" src=\"%@\" type=\"application/x-shockwave-flash\" \ width=\"%0.0f\" height=\"%0.0f\"&gt;&lt;/embed&gt;\ &lt;/body&gt;&lt;/html&gt;"; NSString *html = [NSString stringWithFormat:youTubeVideoHTML, url, frame.size.width, frame.size.height]; [webView loadHTMLString:html baseURL:nil]; [loadedIconsArray addObject:webView]; } </code></pre> <p><code>loadedIconsArray</code> is an <code>NSMutableArray</code></p> <p>the problem:</p> <p>When i load up my YouTube view, it seems as though the main thread is blocked while these <code>UIWebView</code> objects are loading the HTML. after a few seconds, everything is working as expected. I notice that i experience this lag only after installing the application for the first time. all other application/view launches work fine.</p> <p>Why am i experiencing this "lag" or thread blocking?</p> <p>How can i avoid it?</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