在我的原始应用程序中,我有 FeedController 和 FeedCell。单击时我的代码可以正常激活 AVPlayer:FeedController 中的 didSelectItemAt 部分我有以下内容:
{
let details = videoList[indexPath.row]
let videoURL = URL(string: details.video_url!)
var player: AVPlayer? = nil
if let anURL = videoURL {
player = AVPlayer(url: anURL)
}
let playerViewController = AVPlayerViewController()
playerViewController.player = player
present(playerViewController, animated: true) {
player?.play()
}
}
现在,当我在新的集合视图单元格中输入代码时,我在 FeedController 和 FeedCell 之间添加了一个新的集合视图单元格。我收到“使用未解析的标识符‘存在’”。
我知道我需要使用自定义委托,单元格不能呈现控制器,并且我已经创建了委托协议,但我不知道使其工作的正确方法。我努力了 :
func videoSelected(对于单元格:FirstViewCell){
let player: AVPlayer? = nil
let playerViewController = AVPlayerViewController()
playerViewController.player = player
present(playerViewController, animated: true) {
player?.play()
}
}
但是,当我单击时,AVPlayer 弹出正常,但无法播放任何视频。我应该在“didSelectItem”下和 homeController 下写什么?谢谢。