【发布时间】:2010-12-03 16:26:08
【问题描述】:
我有一个 UITableView,它显示 YouTube 数据,例如视频标题和日期。我还为每个加载 HTML 字符串的 UITableViewCell 显示一个 UIWebView(75x75px)。
这里是- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath的相关代码:
UIWebView *iconView = (UIWebView*)[cell.contentView viewWithTag:2];
[self embedYouTube:videoUrl frame:CGRectMake(0, 0, 75, 75) webView:iconView];
和embedYouTube 函数:
- (void)embedYouTube:(NSString*)url frame:(CGRect)frame webView:(UIWebView*)webView {
if([loadedIconsArray containsObject:webView])
return;
NSString *youTubeVideoHTML = @"<html><head>\
<body style=\"margin:0\">\
<embed id=\"yt\" src=\"%@\" type=\"application/x-shockwave-flash\" \
width=\"%0.0f\" height=\"%0.0f\"></embed>\
</body></html>";
NSString *html = [NSString stringWithFormat:youTubeVideoHTML, url, frame.size.width, frame.size.height];
[webView loadHTMLString:html baseURL:nil];
[loadedIconsArray addObject:webView];
}
loadedIconsArray 是 NSMutableArray
问题:
当我加载我的 YouTube 视图时,似乎主线程被阻止,而这些 UIWebView 对象正在加载 HTML。几秒钟后,一切都按预期工作。我注意到我只有在第一次安装应用程序后才会遇到这种滞后。所有其他应用程序/视图启动工作正常。
为什么我会遇到这种“滞后”或线程阻塞?
如何避免?
【问题讨论】:
标签: iphone objective-c ios uiwebview