我目前有一個桌面視圖嵌入在自定義單元格內的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];
}