gpt4 book ai didi

iphone - UITableView iPhone App 中的 YouTube 视频

转载 作者:可可西里 更新时间:2023-11-01 04:42:51 24 4
gpt4 key购买 nike

我目前有一个表格 View ,其中嵌入了自定义单元格中的 YouTube 视频。

我这样做是因为根据我的研究,这似乎是允许在不离开我的应用程序的情况下加载视频的唯一方法。

问题是这样的:

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

当我向下滚动视频列表时,它一直需要加载缩略图。

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

有没有人对更好的方法或让表格单元格保留数据而不是替换数据的方法有任何建议?

我的代码是这样的:

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;

干杯

最佳答案

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

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

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

return [cellArray objectAtIndex:indexPath.row];

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

关于iphone - UITableView iPhone App 中的 YouTube 视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5210280/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com