在我的原始应用中,我有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之间添加一个新的集合视图单元格。我收到“使用未解决的标识符'present'”。
我知道我需要使用自定义委托,一个单元不能提供控制器,并且已经创建了委托协议,但是我不知道使它工作的正确方法。我已经尝试过:
func videoSelected(用于单元格:FirstViewCell){
let player: AVPlayer? = nil
let playerViewController = AVPlayerViewController()
playerViewController.player = player
present(playerViewController, animated: true) {
player?.play()
}
}
但是,当我单击时,AVPlayer会很好地弹出,但是无法播放任何视频。我应该在“ didSelectItem”下和homeController下写什么?谢谢。