在我的tableviewcell
我有一個UIImageView
。此ImageView
用於向用戶呈現錄製視頻的縮略圖。以下是我如何設置ImageView
。TableViewController和自定義UITableViewCell的關係
@IBOutlet weak var thumbImageView: UIImageView! {
didSet {
let videoUrl = NSURL(string: Link to Video)
var thumbImage: UIImage?
let asset = AVAsset(URL: videoUrl!)
let assetImgGenerate = AVAssetImageGenerator(asset: asset)
assetImgGenerate.appliesPreferredTrackTransform = true
let time = CMTimeMake(asset.duration.value/3, asset.duration.timescale)
if let cgImage = try? assetImgGenerate.copyCGImageAtTime(time, actualTime: nil) {
thumbImage = UIImage(CGImage: cgImage)
print("Got Thumb")
self.thumbImageView.image = UIImage(CGImage: cgImage)
}
}
}
在我TableViewCell
我也有:
var URL: String? {
didSet {
print(URL!)
}
}
在我TableView
我打電話,我已存儲的視頻用戶的鏈接救了我的S3服務器上解析數據庫。在CellForRowAtIndexPath
方法我現在用的是PFObject提供的網址我的網址變量:
cell.URL = Some URL
我想有工作:
let videoURL = NSURL(string: self.URL!)
但我正在逐漸爲零,當我運行代碼將URL傳遞給thumbImageView。我還有另外一種方法來設置它嗎?
任何幫助表示讚賞!
這樣一個簡單的解決方案!謝謝 – bobawgg