我目前有一个桌面视图嵌入在自定义单元格内的YouTube视频。在tableview单元格中的Youtube视频
我这样做是因为从我的研究中,它似乎是允许视频加载而不离开我的应用程序的唯一方法。
问题是这样的
缩略图需要一段时间才能加载。当我向下滚动视频列表时,它不得不加载缩略图。如果我向后滚动,它会再次尝试加载视频缩略图。
有没有人有任何建议,要么这样做的更好的方法,或获得表格单元格保持数据,而不是取代它的方式?
我的代码如下所示:
-(UITableViewCell *)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath{
static NSString *MyIdentifier = @"MyIdentifier";
YouTubeCell *cell = (YouTubeCell*)[tableView dequeueReusableCellWithIdentifier:MyIdentifier];
if(cell ==nil){
cell = [[[YouTubeCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyIdentifier] autorelease];
}
NSDictionary *dic = [youTubeArr objectAtIndex:indexPath.row];
[cell updateCellData:dic];
return cell;
}
-(void)updateCellData:(NSDictionary*)dict
{
NSDictionary *tempDic = [dict objectForKey:@"video"];
self.titleLbl.text = [tempDic objectForKey:@"title"];
NSString *viewCountStr = [NSString stringWithFormat:@"%@ views -",[tempDic objectForKey:@"viewCount"]];
viewCountLbl.text = viewCountStr;
uploadedDateLbl.text = [tempDic objectForKey:@"uploaded"];
NSDictionary *videoDic = [tempDic objectForKey:@"player"];
NSString *videoStr = [NSString stringWithFormat:@"%@",[videoDic objectForKey:@"default"]];
NSString *embedHTML =
@"<html><head>\
<body style=\"margin:0\">\
<embed id=\"yt\" src=\"%@\" type=\"application/x-shockwave-flash\" \
width=\"%0.0f\" height=\"%0.0f\"></embed>\
</body></html>";
// videoView = [[UIWebView alloc] initWithFrame:CGRectMake(3, 5, 100, 60)]; initialzed in ///initwithstyle of cell
NSString *html = [NSString stringWithFormat:embedHTML, videoStr, videoView.frame.size.width, videoView.frame.size.height];
[videoView loadHTMLString:html baseURL:nil];
}