我的 UITableView 有一个大问题。当用户点击特定单元格时,我试图显示视频。但我的问题是当我滚动表格时,视频也出现在其他单元格中。我怎样才能防止这种情况?
这是我的代码(我正在使用 BrihgtCove 显示视频)
class CatagoryOne: UITableViewController,BCOVPlaybackControllerDelegate {
// MARK: - BrightCove Properties
let catalogService = BCOVCatalogService(token:kViewControllerCatalogToken)
var playbackController :BCOVPlaybackController?
var avpvs : AVPlayerViewController?
static var selectedRow : Int?
required init?(coder aDecoder: NSCoder) {
let manager = BCOVPlayerSDKManager.sharedManager();
avpvs = AVPlayerViewController()
playbackController = manager.createPlaybackControllerWithViewStrategy(manager.defaultControlsViewStrategy())
super.init(coder: aDecoder)
playbackController!.analytics.account = kPublistherID
playbackController!.delegate = self
playbackController!.autoAdvance = true
playbackController!.autoPlay = true
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("VideoItemCell", forIndexPath: indexPath) as! NewVideoItemCell
print("indexPath on cellForRowAtIndexPath = " ,indexPath.row)
print("selectedRow on cellForRowAtIndexPath = " ,CellReUseModel.selectedRow)
// Configure the cell...
configureVideoListCell(cell, atRow: indexPath.row)
return cell
}
func configureVideoListCell (cell : NewVideoItemCell,atRow : Int) {
//cell.backgroundColor = Colors.videoListItemColor
cell.videoTitle.textColor = Colors.videoListTextColor
cell.videoTitle.text = videoModel.titleOfVideoList(atRow)
//cell.thumbNail.image = videoModel.thumbnailForVideoItem(atRow)
}
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
let cell = tableView.cellForRowAtIndexPath(indexPath) as! NewVideoItemCell
print("indexpath Row = " ,indexPath.row)
CellReUseModel.selectedRow = indexPath.row
print("Selected Row = " ,CellReUseModel.selectedRow)
//self.tableView.reloadData()
// the Code that plays the video
self.addChildViewController(avpvs!)
avpvs!.view.frame = cell.contentView.bounds
avpvs!.view.autoresizingMask = [.None]
avpvs!.videoGravity = AVLayerVideoGravityResizeAspectFill
cell.contentView.addSubview(self.avpvs!.view)
avpvs!.didMoveToParentViewController(self)
requestContentFromCatalog()
}
}
请在这件事上给予我帮助 :(