如何在属于 UITableViewCell 一部分的 UIWebView 中使用 YouTube 视频的嵌入标签
我可以成功使用嵌入标签将 YouTube 视频嵌入到不属于表格单元格的 UIWebView 中。
我可以在作为表格单元格一部分的 UIWebView 中成功设置 html。
但是,使用嵌入标签链接到 YouTube 视频在作为表格单元格一部分的 UIWebView 中设置 html 对我来说不起作用。
我的自定义 UITableViewCell 类中的代码如下所示:
NSString *embedHTML = @"\
<html><body>\
<embed id=\"yt\" src=\"%@\" type=\"application/x-shockwave-flash\" \
width=\"%0.0f\" height=\"%0.0f\"></embed>\
</body></html>";
CGRect frame = self.webView.bounds;
NSString *html = [NSString stringWithFormat:embedHTML, urlString, frame.size.width, frame.size.height];
[self.webView loadHTMLString:html baseURL:nil];
如果我替换“
测试
”这样简单的东西,它就会像我期望的那样出现。如果我在具有 webView 的非表视图控制器中使用带有嵌入标记的代码片段,它就可以正常工作。
我是否做错了什么,或者 UITableViewController 和关联的类只是不允许我这样做?
谢谢, Doug
--------- 2010 年 12 月 8 日更新
我可以成功使用“
所以,问题标题仍然准确,但我不再怀疑 YouTube 链接有很大不同。
I can successfully use the embed tag to embed a youtube video in a UIWebView that is NOT part of a table cell.
I can successfully set the html in a UIWebView that IS part of a table cell.
But, setting the html in a UIWebView that IS part of a table cell using the embed tag to link to a youtube video does not work for me.
The code in my custom UITableViewCell class looks like this:
NSString *embedHTML = @"\
<html><body>\
<embed id=\"yt\" src=\"%@\" type=\"application/x-shockwave-flash\" \
width=\"%0.0f\" height=\"%0.0f\"></embed>\
</body></html>";
CGRect frame = self.webView.bounds;
NSString *html = [NSString stringWithFormat:embedHTML, urlString, frame.size.width, frame.size.height];
[self.webView loadHTMLString:html baseURL:nil];
If I replace the "<embed ...>" with something simple like "<p>testing</p>", it shows up just like I expect it to.
If I use the code snippet with the embed tag in a non-table view controller that has a webView, it works just fine.
Am I doing something wrong, or are the UITableViewController and associated classes just not going to let me do this?
Thanks,
Doug
--------- Update on 08-Dec-2010
I can successfully use the "<embed ...>" or "<video ...>" tags in a UIWebView that is part of a UITableViewCell EXCEPT for YouTube videos.
So, the question title is still accurate, but I no longer have any doubt that there is something much different about the YouTube link.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我重新开始一个新项目并让它发挥作用。
由于第一个项目只是一个原型,我认为我做了一些破坏行为的事情——现在不确定是什么,事情看起来大致相同。
I started over with a fresh project and got it working.
Since the first project was just a prototype, I assume I did something that broke the behavior -- not sure what right now, things look roughly the same.