UITableView iPhone App中的YouTube视频 [英] YouTube videos inside UITableView iPhone App

查看:155
本文介绍了UITableView iPhone App中的YouTube视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前在自定义单元格中嵌入了youtube视频的tableview。

I currently have a tableview with youtube videos embedded inside of the custom cells.

我之所以这样做是因为从我的研究中看来这似乎是允许视频加载而不离开我的应用程序的唯一方法。

I did this because from my research it seemed like the only way to allow the videos to load without leaving my application.

问题在于:

缩略图需要一段时间才能加载。

The thumbnails take a while to load.

当我向下滚动视频列表时,它不断加载thunbnails。

As I scroll down the list of videos, it keeps having to load the thunbnails.

如果我向上滚动...它会再次尝试加载视频缩略图。

If I scroll back up...it tries to load the video thumbnails yet again.

有没有人对更好的方法有什么建议,或者让表格单元格保留数据而不是替换它的方法?

Has anyone got any suggestions on either better ways of doing this, or ways of getting the table cells to keep the data and not replace it?

我的代码如下所示:

CustomVideoCell *cell = (CustomVideoCell *)[tableView dequeueReusableCellWithIdentifier:@"CustomVideoCell"];

if (cell == nil) {

UIViewController *temporaryController = [[UIViewController alloc] initWithNibName:@"CustomVideoCell" bundle:nil];

cell = (CustomVideoCell *)temporaryController.view;

[temporaryController release];


GDataEntryBase *entry = [[self.feed entries] objectAtIndex:indexPath.row];
NSString *title = [[entry title] stringValue];
NSString *videoID = [[(GDataEntryYouTubeVideo *)entry mediaGroup] videoID];


NSString *htmlString = 
[
 [NSString alloc] 
 initWithFormat:@"<html><head><meta name = \"viewport\" content = \"initial-scale = 2.0, user-scalable = no, width = 110\"/></head><body style=\"background:#000;margin-top:0px;margin-left:0px\"><div><object width=\"110\" height=\"90\"><param name=\"movie\" value=\"http://www.youtube.com/v/%@&f=gdata_videos&c=ytapi-my-clientID&d=nGF83uyVrg8eD4rfEkk22mDOl3qUImVMV6ramM\"></param><param name=\"wmode\" value=\"transparent\"></param><embed src=\"http://www.youtube.com/v/%@&f=gdata_videos&c=ytapi-my-clientID&d=nGF83uyVrg8eD4rfEkk22mDOl3qUImVMV6ramM\" type=\"application/x-shockwave-flash\" wmode=\"transparent\" width=\"110\" height=\"90\"></embed></object></div></body></html>", 
 videoID, videoID
 ];


[[[cell.web subviews] lastObject] setScrollEnabled:NO];
[cell.web loadHTMLString:htmlString baseURL:[NSURL URLWithString:@"http://www.website.com"]];

cell.title.text = title;

干杯

推荐答案

在这些情况下我做的是创建一个函数,用我需要的表格单元格填充一个可变数组。

然后在方法中:

What I do in these cases is creating a function which fills a mutable array with the table cells I need.
Then in the method:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

我根据索引返回数组中的单元格:

I return the cell in the array based on the index like this:

return [cellArray objectAtIndex:indexPath.row];

我用这种方式创建了非常大的可变数组并且没有内存问题,但我想这取决于其他你的应用中的东西。

I have created very large mutable arrays this way and had no memory issues but I guess it depends on other things in your app.

这篇关于UITableView iPhone App中的YouTube视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆