您只需要一个 VC 即可显示您拥有的众多视频。
假设你有一个这样的模型:
struct Video {
let videoLink: URL
let description: String
}
您的表视图控制器使用一个名为videos 的Videos 数组作为其数据源。
在您的didSelectRowAt 方法中,您可以获取所选视频并以所选视频作为发送者执行segue:
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let videoSelected = videos[indexPath.row]
performSegue(withIdentifier: "showVideo", sender: videoSelected)
}
现在创建一个 VideoViewController.swift 文件并执行以下操作:
class VideoViewController: UIViewController {
var video: Video!
// write code for this VC to display not a specific video, but "self.video"
// For example, instead of setting the label's text to a hardcoded description, set it to "self.video.description"
}
然后,返回您的表格视图控制器,并覆盖 prepareForSegue:
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if let vc = segue.destination as? VideoViewController {
vc.video = sender as! Video
}
}