【发布时间】:2015-09-13 16:36:43
【问题描述】:
我正在尝试找到一种在UICollectionView 上添加一组 youtube 视频缩略图的方法。但是在我尝试缩略图(图像)的方式上,没有显示出来,而且我还没有找到在NSData 上添加 URL 集合(数组)的方法。
或者如果有其他方法可以做到这一点,比如使用 Youtube API。
顺便提一下,我不了解 Obj-C,所以 Obj-C 中的任何代码都不会很有帮助。
这是我的代码
var videoName:[String] = ["First Video", "Second Video", "Third Video"]
var videoImage:[String] = ["thumbnail1","thumbnail2","thumbnail3"]
let thumbnail1 = NSURL(string: "https://www.youtube.com/watch?v=sGF6bOi1NfA/0.jpg")
let thumbnail2 = NSURL(string: "https://www.youtube.com/watch?v=y71r1jhMdRk/0.jpg")
let thumbnail3 = NSURL(string: "https://www.youtube.com/watch?v=qfsRZsvraD8/0.jpg")
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell: SongCollectionView = collectionView.dequeueReusableCellWithReuseIdentifier("Cell", forIndexPath: indexPath) as! SongCollectionView
cell.labelCell.text = videoName[indexPath.row]
let imageData = NSData(contentsOfURL: /*videoImage[indexPath.row]*/ thumbnail1!) // in the commented section I am trying to add an array of strings which contains thumbnail URL's
cell.imageCell.image = UIImage(data: imageData!)
return cell
}
【问题讨论】:
-
https://www.youtube.com/watch?v=sGF6bOi1NfA/0.jpg重定向到视频,并且不显示缩略图。您确定您使用的网址正确吗? -
是的,你是对的,这是一个愚蠢的错误 thnx
-
请问正确的网址是什么?
标签: swift youtube uicollectionview thumbnails youtube-data-api